This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ubuntu tree | |
sudo apt-get install tree | |
# print to terminal in tree format | |
$ tree [DIRECTORY] | |
# example [csv] directory outputs: | |
├── csv | |
│ ├── CVS | |
│ │ ├── Entries |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array.prototype.filter | |
function containsTest(value) { | |
return value.indexOf('test') != -1; | |
} | |
var a = ['a', 'b', 'c', 'a_test']; | |
var filtered = a.filter(containsTest); | |
// filtered = ['a_test']; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Run PHP in terminal / command line: | |
* $ php -a | |
*/ | |
// Get input from stdin command line | |
$handle = fopen ("php://stdin","r"); | |
$line = fgets($handle); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nvm - node version manager | |
$ nvm use 0.0.1 # select 0.0.1 from installed version | |
$ nvm ls # list versions installed | |
$ nvm ls-remote # list versions available | |
$ nvm alias default 0.0.1 # set 0.0.1 version as default | |
$ nvm use default | |
$ nvm help | |
# node - node js package (nodejs ubuntu 14.04) | |
$ node -v # show version |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# netstat | |
$ netstat -tulpn # [--tcp|-t] [--udp|-u] [--listening|-l] [--numeric|-n] [--program|-p] | |
# Active Internet connections (only servers) | |
# Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name | |
# tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 22535/mysqld | |
# tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 16902/sshd | |
# tcp6 0 0 :::80 :::* LISTEN 4969/apache2 | |
# tcp6 0 0 :::22 :::* LISTEN 16902/sshd | |
# udp 0 0 0.0.0.0:15213 0.0.0.0:* 580/dhclient |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Log charCodes: string from keyboard events | |
for(i=0; i<222; i++){ | |
console.log(i + ': ' + String.fromCharCode(i)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Get default data source and log last run SQL query | |
*/ | |
function getLastQuery() { | |
$dbo = ConnectionManager::getDataSource('default'); | |
$logs = $dbo->getLog(); | |
$lastLog = end($logs['log']); | |
return $lastLog['query']; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Time difference logging function | |
* | |
* $start time from PHP microtime(true) // returns seconds as float | |
* $end time from PHP microtime(true) | |
*/ | |
function logTimeDiff($start, $end) { | |
$seconds = $end - $start; | |
$milli = $seconds / 1000; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Parse JSON using JavaScript | |
*/ | |
// arbitrary string "bunch o' junk" | |
var string = '{"menu":{"id":"file","value":"File","popup":{"menuitem":[{"value":"New","onclick":"CreateNewDoc()"},{"value":"Open","onclick":"OpenDoc()"},{"value":"Close","onclick":"CloseDoc()"}]}}}'; | |
JSON.parse(string); | |
// parsed and printed in a more "human readable" format | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tabular view of data with scrolling | |
mysql> pager less -SFX | |
mysql> SELECT * FROM sometable; |