Thursday, 16 July 2015

View train times in real-time in your console

View train times in real-time in your console


trainscli

View train times in real-time in your console
Alter WKI for the station code of your location station and it should print the times for you.
i've forked this from mattshirtliffe/trainscli
altered it only slightly to remove an error from BS moaning about the type of data to parse and removed whitespace on print out.




PHP - Convert UTC to BST

Convert UTC to GMT Date PHP
123
$date = "2015-05-31";
$d=strtotime($date);
$newdate = date('d-m-Y',$d);

Grab large image from pic.twitter.com in php

123456789101112131415161718192021222324252627282930313233343536
<?php
// Defining the basic scraping function
function scrape_between($data, $start, $end){
$data = stristr($data, $start); // Stripping all data from before $start
$data = substr($data, strlen($start)); // Stripping $start
$stop = stripos($data, $end); // Getting the position of the $end of the data to scrape
$data = substr($data, 0, $stop); // Stripping all data from after and including the $end of the data to scrape
return $data; // Returning the scraped data from the function
}
function curl($url) {
// Assigning cURL options to an array
$options = Array(
CURLOPT_RETURNTRANSFER => TRUE, // Setting cURL's option to return the webpage data
CURLOPT_FOLLOWLOCATION => TRUE, // Setting cURL to follow 'location' HTTP headers
CURLOPT_AUTOREFERER => TRUE, // Automatically set the referer where following 'location' HTTP headers
CURLOPT_CONNECTTIMEOUT => 120, // Setting the amount of time (in seconds) before the request times out
CURLOPT_TIMEOUT => 120, // Setting the maximum amount of time for cURL to execute queries
CURLOPT_MAXREDIRS => 10, // Setting the maximum number of redirections to follow
CURLOPT_USERAGENT => "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1a2pre) Gecko/2008073000 Shredder/3.0a2pre ThunderBrowse/3.2.1.8", // Setting the useragent
CURLOPT_URL => $url, // Setting cURL's URL option with the $url variable passed into the function
);
$ch = curl_init(); // Initialising cURL
curl_setopt_array($ch, $options); // Setting cURL's options using the previously assigned array data in $options
$data = curl_exec($ch); // Executing the cURL request and assigning the returned data to the $data variable
curl_close($ch); // Closing cURL
return $data; // Returning the data from the function
}
$scraped_page = curl("pic.twitter.com/mhSJp6qkmP");
$scraped_data = scrape_between($scraped_page, '<meta property="og:image" content="', ':large">');
echo $scraped_data;
?>

Change text inside a mysql colum

Replace Word with another word using MYSQL
123
To find a string in a certain field and replace it with another string:
 
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');

Thursday, 12 March 2015

Free UK SMS via Raspberry Pi

Just a reminder.


you can send free SMS via the API or via the webpage to any UK number.

Just remember don't abuse the service or you end up on a rather disturbing webpage and dont use it to sell on gumtree if your a scammer from nigeria.

it can accept incoming sms so you can send a sms and it will then be either emailed to you or send it on to your own script and do get it to run some sort of command.

some ideas.


Enjoy!

Migrate all mysql databases to new server!

This is more for me as a reminder.


I had to move my database for projects i had done on my Model B Pi and move them to my new PI 2 B.

Found this super command!!!


mysqldump -u root -pPASSWORD --all-databases | sshUSER@NEW.HOST.COM 'cat - | mysql -u root -pPASSWORD'

Such an amazing command you run this on the OLD server.

So change the first password for your current root mysql password  change USER in the SSH part to your root user on the new system and change the @ newhost to the ip/domain for the new server and then the last part change the password to the new root password.

ONE MAJOR THING!

the moment you do this tho it does change the mysql root password to the same as your old one!

Boom. This ran surprisingly quickly for me, and you can of course just as easily use this method to transfer a single database.
Three gotchas:
  • If the link dies, you need to start again, so don’t do this over a flakey connection, and I suggest you run the command in a screen if the first server isn’t localhost.
  • You need to restart the database server on the target machine for the new users and privileges to come into effect.
  • On Debian, you may see an error along the lines of:
    Got error: 1045: Access denied for user ‘debian-sys-maint’@’localhost’ (using password: YES) when trying to connect
    Fix this by executing the command:
    GRANT ALL PRIVILEGES ON *.* TO 'debian-sys-maint'@'localhost' IDENTIFIED BY 'THEPASSWORD' WITH GRANT OPTION;
    Where THEPASSWORD is the password found in /etc/mysql/debian.cnf
One final note: this will only work if both servers are the same major version number. 

also you can change ----all-databases  to --database 
this will allow you to move one or more databases!

found @ https://www.marcus-povey.co.uk/2013/03/25/moving-a-mysql-database-between-servers-using-a-single-ssh-command/

Wednesday, 5 November 2014

IPTV / UPNPD for raspberry pi

Check out my github!

https://github.com/txt3rob/xupnpd-raspberry-armhf



 README.md


xupnpd-raspberry-armhf

This is just a DEB file built on a Raspberry PI!

I AM NOT THE AUTHOR OF XUPNPD SO I OFFER NO SUPPORT JUST AN INSTALL FILE!

For all info on xupnpd - http://xupnpd.org/

xupnpd - eXtensible UPnP agent

This program is a light DLNA Media Server which provides ContentDirectory:1 service for sharing IPTV unicast streams over local area network (with udpxy for multicast to HTTP unicast conversion).
The program shares UTF8-encoded M3U playlists with links over local area network as content of the directory.
You can watch HDTV broadcasts (multicast or unicast) and listen Internet Radio in IP network without transcoding and PC.
Multicast IPTV without transcoding (xupnpd+udpxy) was tested with:
Ubuntu 10.04 (Linux, IA-32) as Media Server
D-Link DIR-320 (DD-WRT v24 preSP2 13064, mipsel), ASUS WL-500gP, Asus N-16, TP-LINK WR841ND as Media Server
Sony PlayStation 3 as UPnP player
IconBit HDS4L, WDTV Live as UPnP player
HTC Desire, HTC Sensation as UPnP player (Android 2.2 + UPnPlay/BubbleUPnP + VPlayer/MX Video Player)
Samsung UE46D6510, Samsung UE40D5000PW, Samsung LE40c550, Samsung LE40B650, Samsung UE40C6000, Samsung US46ES6100, Samsung UE32EH6037, LG PZ750, Sony 26EX231, Philips 47pfl7606h as player
Microsoft Windows Media Player 11 as UPnP player
Ubuntu 10.04 with VideoLAN as UPnP player

Features

Builtin DLNA/UPnP media server for sharing local media files and external IPTV/Radio streams
Builtin multicast proxy for MPEG-TS streams
YouTube, Vimeo and GameTrailers plugins (HD)
No transcoding
HDTV ready
Parent control (Access Control List)
Web-based user interface
LUA scripting
For all support see http://xupnpd.org/

Amazon

Donate

Donate Towards More Raspberry PI's for Projects