Skip to content

Instantly share code, notes, and snippets.

@ceme
ceme / check_url.sh
Created March 5, 2017 19:13
Chatty curl to output file with cheap argument host validation, no usefull usage instructions, and hardcoded output file name, pretty rudimentery code.
#! /bin/sh
function check {
if [ $? -ne 0 ] ; then
echo "Error occurred getting URL $1;"
if [ $? -eq 6 ]; then
echo "Unable to reslove host"
fi
if [ $? -eq 7 ]; then
echo "Unable to contact host"
@ceme
ceme / Tower_Of_Hanoi_recurrsive.txt
Created March 3, 2017 23:00
Tower Of Hanoi generic recurrsive solution
function move(n, from, to, using)
{
if (n = 1)
print (“Move disk from “, from, “ to “, to);
else
{
move (n-1, from, using, to);
move(1, from, to, using);
move(n-1, using, to, from);
}
/*
* @param Number timecode (milliseconds)
* @return String h:m:s (zero padded to two spaces)
* Usage: timecodeDisplay(11282000) -> "03:08:02"
*/
function timecodeDisplay(timecode) {
var seconds = timecode / 1000 % 60;
var secondsDisp = (seconds <= 9) ? '0' + seconds : '' + seconds;
var minutes = (((timecode / 1000) - seconds) / 60) % 60;
var minutesDisp = (minutes <= 9) ? '0' + minutes : '' + minutes;
@ceme
ceme / my_promise.js
Last active November 23, 2015 22:27
Simple Implementation of the Promises API in JS
var myPromise = function(arg) {
return new Promise(function(resolve, reject) {
if (arg === true) {
resolve('it\'s all good');
} else {
reject('no good, buddy');
}
});
}
var setting = confirm("Press 'OK' to succeed or 'Cancel' to fail");
@ceme
ceme / npm_node_update_commands.txt
Created November 19, 2015 22:56
Update existing node version on OSX command line with npm
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
@ceme
ceme / cli_npm_list_local
Created August 13, 2015 15:26
List locally installed npm modules
npm list -g --depth=0
@ceme
ceme / euclidean_algorithm.js
Created June 19, 2015 22:15
Euclidean algorithm implemented in JavaScript - demo: http://jsfiddle.net/86znwp1y/
function gcd(a, b) {
return c = (b == 0) ? a : gcd (b, a % b);
}
@ceme
ceme / command_list_running_on_port
Created December 18, 2014 21:05
Mac OS X: find the program running on a port
sudo lsof -i :80 # checks port 80
@ceme
ceme / grep_for_js
Created November 10, 2014 23:24
Grep text file for .js lines
cat vlfiles.txt | grep .js | uniq
@ceme
ceme / svn_resolve_all
Last active August 29, 2015 14:07
SVN Resolve Tree Conflicts
svn resolve --accept working -R <path>