PHP: Get URL Content Using PHP Curl

/* gets the data from a URL */
function get_data($url)
{
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch,CURLOPT_URL,$url);
  curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

Source: http://davidwalsh.name/download-urls-content-php-curl

Posted in Languages | Tagged , | Leave a comment

Netgear: Using WNDR3700 as Wireless Access Point

Basic Configuration
  • WNDR3700 needs to be configured using its installation CD
  • After it is set to factory default, its default IP is 192.168.1.1
Access Point Setup
  • Plug your Internet connection into the WAN port (yellow) on the WNDR3700
  • Power cycle the router
  • The router will get a WAN IP and distribute IPs as necessary to connected clients
Posted in Networking | Leave a comment

Mac: How To Shutdown Using Command Line

Crontab (shutdown every morning at 3am):

0 3 * * * /sbin/shutdown -h now
Posted in Apple | Leave a comment

Linux: Send Process To Background And Logout

While process is running, press CTRL-z, then...
$ bg
(the output may come to foreground again, but you can logout now
and the process will continue running in the background)
Posted in Linux | Leave a comment

Xbox: Westinghouse LCD TV and Xbox 360 Universal Remote

Use Sony Xbox Remote Codes: 0123

Also, if PC input sound fails, toggle the mute on the LCD TV.

Posted in Everything Else | Leave a comment

Linux: Using Daemonize To Run User Processes In The Background

You must use full paths to all arguments for daemonize.

As of now, daemonize must be downloaded and compiled, it does not exist in APT.

$ daemonize /usr/full/path/to/node /home/full/path/to/app.js
Posted in Linux | Leave a comment

Subversion: svn undo delete before commit

svn revert file [file] [file] ...
Posted in Everything Else | Leave a comment

Linux: How To Fix “node js openssh not found”

apt-get install -y pkg-config
Posted in Linux | Leave a comment

Linux: How To Find Disk IO Usage Per Process

Sendmail sometimes uses a lot of disk IO by kicking off this process:

  215 root      20   0     0    0    0 D    1  0.0 187:49.63 [jbd2/dm-0-8]

Tools you can try using:

iostat
iotop

Before:

# iostat 1
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.57    0.30    1.28   25.45    0.00   72.40

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda             145.50        22.54      1432.56   38268380 2431954938
dm-0            370.18        22.48      1432.37   38162397 2431624576
dm-1              0.06         0.05         0.18      79200     308588

After:

# /etc/init.d/sendmail stop
 * Stopping Mail Transport Agent (MTA) sendmail                                                        [ OK ]
# iostat 1
Linux 2.6.38-11-server (web201) 	09/21/2011 	_x86_64_	(4 CPU)

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           0.00    0.00    0.00    0.00    0.00  100.00

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sda               0.00         0.00         0.00          0          0
dm-0              0.00         0.00         0.00          0          0
dm-1              0.00         0.00         0.00          0          0

Sendmail alternative:

# apt-get install -y postfix
(blah blah blah)
 * Starting Postfix Mail Transport Agent postfix         [ OK ]
# sendmail -t
To:me@gmail.com
Subject: test after postfix installed
do it
(this works)
Posted in Linux | Leave a comment

Wireshark: Common Filters

DISPLAY FILTER EXPLANATION EXAMPLE
eth.addr source or destination mac-address eth.addr == 00:1a:6b:ce:fc:bb
eth.src source mac-address eth.src == 00:1a:6b:ce:fc:bb
eth.dst destination mac-address eth.dst == 00:1a:6b:ce:fc:bb
arp.dst.hw_mac target mac-address arp.dst.hw_mac == 00:1a:6b:ce:fc:bb
arp.dst.proto_ipv4 target IPv4 address arp.dst.proto_ipv4 == 10.10.10.10
arp.src.hw_mac sender mac-address arp.src.hw_mac == 00:1a:6b:ce:fc:bb
arp.src.proto_ipv4 sender IPv4 address arp.src.proto_ipv4 == 10.10.10.10
vlan.id vlan ID vlan.id == 16
ip.addr source or destination IPv4 address ip.addr == 10.10.10.10
ip.dst destination IPv4 address ip.addr == 10.10.10.10
ip.src source IPv4 address ip.src == 10.10.10.10
ip.proto IP protocol (decimal) ip.proto == 1
ipv6.addr source or destination IPv6 address ipv6.addr == 2001::5
ipv6.src source IPv6 address ipv6.addr == 2001::5
ipv6.dst destination IPv6 address ipv6.dst == 2001::5
tcp.port source or destination TCP port tcp.port == 20
tcp.dstport destination TCP port tcp.dstport == 80
tcp.srcport source TCP port tcp.srcport == 60234
udp.port source or destination UDP port udp.port == 513
udp.dstport destination UDP port udp.dstport == 513
udp.srcport source UDP port udp.srcport == 40000
fr.dlci Frame-Relay DLCI number fr.dlci == 112
icmp.type ICMP type code (decimal) icmp.type == 8
vtp.vlan_info.vlan_name VLAN name vtp.vlan_info.vlan_name == TEST
bgp.originator_id BGP id (IPv4 address) bgp.originator_id == 192.168.10.15
bgp.next_hop BGP Next Hop (IPv4 address) bgp.next_hop == 192.168.10.15
rip.ip RIP IPv4 address rip.ip == 200.0.2.0
ospf.advrouter OSPF advertising router ID ospf.advrouter == 192.168.170.8
eigrp.as EIGRP autonomous system number eigrp.as == 100
hsrp.virt_ip HSRP virtual IP address hsrp.virt_ip == 192.168.23.250
vrrp.ip_addr VRRP virtual IP address vrrp.ip_addr == 192.168.23.250
zebra.dest4 ZEBRA destination IPv4 address zebra.dest4 == 10.10.10.10
wlan.addr source or destination MAC address wlan.addr == 00:1a:6b:ce:fc:bb
wlan.sa source MAC address wlan.sa == 00:1a:6b:ce:fc:bb
wlan.da destination MAC address wlan.da == 00:1a:6b:ce:fc:bb

Source: firstdigest.com

Posted in Networking | Leave a comment

Linux: How To Play AVI Files

APT packages needed to play FFmpeg .avi files:

p   gstreamer0.10-ffmpeg            - FFmpeg plugin for GStreamer
p   gstreamer0.10-plugins-bad       - GStreamer plugins from the "bad" set
Posted in Linux | Leave a comment

VIM: Swap Left Hand Directional Keys With Right Hand Command Keys

Reduce usage in your right hand using these mappings.

- Mirror up and down keys
- Shift left and right keys to the left hand
- 's' (change one character and insert) becomes 'h'
- 'd' ('dd' deletes a line) becomes 'k'
- 'f' ('ff' moves cursor to end of line) becomes 'j'
- 'g' (does nothing by itself) becomes 'l'
- 'noremap' avoids infinite loop
~/.vimrc:

" Map Right Hand Directionals to Left Hand Commands
noremap s h
noremap d k
noremap f j
noremap g l

" Map Left Hand Commands to Right Hand Directionals
noremap h s
noremap k d
noremap j f
noremap l g
Posted in Linux | Leave a comment

Apache: Redirect All Queries From HTTP to HTTPS

  RedirectMatch (.*) https://host.example.com$1
Posted in Everything Else | Leave a comment

Ubuntu: CMake “RPM package requires rpmbuild executable”

apt-get install -y rpm
Posted in Linux | Tagged , | Leave a comment

Linux: Backup Entire Directories With Revision Control Using Subversion SVN

General steps (for example, the /etc directory)
  1. Install Ubuntu Server
  2. Log in and sudo bash.
  3. Import the /etc directory into your SVN repository.
  4. Check out the new directory and call it “/etc.new”
  5. Move out the old directory: “mv /etc /etc.old”
  6. Move in the new directory: “mv /etc.new /etc”
  7. Fix sudoers permissions: “chmod 0440 /etc/sudoers /etc/sudoers.d/README”
  8. Reboot

Posted in Linux | Leave a comment

Linux: MySQL Set Root Password

For Windows, do this:

shell> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'%' = PASSWORD('newpwd');

The last statement is unnecessary if the mysql.user table has no root account with a host value of %.

For Unix, do this:

shell> mysql -u root
mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'127.0.0.1' = PASSWORD('newpwd');
mysql> SET PASSWORD FOR 'root'@'host_name' = PASSWORD('newpwd');

You can also use a single statement that assigns a password to all root accounts by using UPDATE to modify the mysql.user table directly. This method works on any platform:

shell> mysql -u root
mysql> UPDATE mysql.user SET Password = PASSWORD('newpwd')
    ->     WHERE User = 'root';
mysql> FLUSH PRIVILEGES;

The FLUSH statement causes the server to reread the grant tables. Without it, the password change remains unnoticed by the server until you restart it.

To assign passwords to the root accounts using mysqladmin, execute the following commands:

shell> mysqladmin -u root password "newpwd"
shell> mysqladmin -u root -h host_name password "newpwd"

Those commands apply both to Windows and to Unix. The double quotation marks around the password are not always necessary, but you should use them if the password contains spaces or other characters that are special to your command interpreter.

GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'password';

Source: dev.mysql.com

Posted in Everything Else | Leave a comment

Linux: Subversion SVN+SSH Import New Project

svn import myfolder svn+ssh://kitamura@svn2.cs.lmu.edu/svn/myfolder \
  -m "my comment"
Posted in Linux | Leave a comment

nTop: How To Fix RD: Disabled – unable to create base directory

1. faster one
sudo chown -R nobody:nogroup /var/lib/ntop

2. slower but nicer
sudo chmod 755 /var/lib/ntop
sudo mkdir /var/lib/ntop/rrd
sudo chown -R nobody:nogroup /var/lib/ntop/rrd

and then you can run 

sudo ntop &

and connect to it on http://localhost:3000

Source: Ubuntuforums.org

Posted in Networking | Leave a comment

Subversion: How To Fix “format: permission denied”

# chmod 775 /abspath/to/svnroot
Posted in Everything Else | Leave a comment

Ubuntu Linux: Flush, Clear, Renew DHCP Cache

When all else fails on the client…

# apt-get install -y dhcpcd
# dhcpcd eth0
# dhcpcd.sh: interface eth0 has been configured with new IP=XXX.XXX.XXX.XXX

If it still fails, restart the DHCP server…

# /etc/init.d/dhcp3-server restart

Other things to try on the client:

# dhcpcd -k eth0
# dhcpcd -n eth0
# dhcpcd eth0
# ifconfig (to check)
Posted in Linux | Leave a comment