This file contains 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
// Tree node | |
var Node = function(data) { | |
this.left = null; | |
this.right = null; | |
this.data = data; | |
this.key = data.age; | |
this.parent = null; | |
// Replaces the current node with the data and key of another | |
this.replaceWith = function(replacement) { |
This file contains 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
var str = ''; | |
for(var i=1;i<=100;i++) { | |
var rep = ''; | |
if(i % 3 == 0) rep = 'Fizz'; | |
if(i % 5 == 0) rep += 'Buzz'; | |
str += (rep||i)+', '; | |
} |
This file contains 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
function binarySearch(searchFor, arr, index1, index2) { | |
if(index1 === undefined) index1 = 0; | |
if(index2 === undefined) index2 = arr.length-1; | |
var search = index1+Math.floor((index2-index1)/2); | |
if(arr[search] == searchFor) return true; | |
else if(index2-index1 <= 1) return false; | |
else return binarySearch(searchFor, arr, arr[search] > searchFor ? index1 : search, arr[search] > searchFor ? search : index2); | |
} | |
var found = binarySearch(4, [1,3,6,9,12,17,25,44]); |
This file contains 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
/* | |
HTML: | |
<div id="someParent"> | |
<div id="title"></div> | |
<img id="img"/> | |
</div> | |
Data: | |
var r = {title:'This is a title', img:'http://someimage.jpg'} |
This file contains 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
require './schema.js' | |
mongoose = require "mongoose" | |
mongodb = require "mongodb" | |
sys = require 'sys' | |
lock = require './lock.js' | |
run = require './run.js' | |
# Sample cron | |
# * * * * * /usr/local/bin/node /var/some/dir/cron.js > /var/log/cronjs.log | |
run.attempt('every 1 minute', () -> |
This file contains 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
import java.util.HashMap; | |
import java.util.Iterator; | |
import java.util.Map; | |
import android.content.ContentValues; | |
import android.content.Context; | |
import android.database.Cursor; | |
import android.database.SQLException; | |
import android.database.sqlite.SQLiteDatabase; |
This file contains 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
// Need a handler for toast | |
public void makeToast(String str) { | |
Message status = toaster.obtainMessage(); | |
Bundle datax = new Bundle(); | |
datax.putString("msg", str); | |
status.setData(datax); | |
toaster.sendMessage(status); | |
} | |
public Handler toaster = new Handler(){ |
This file contains 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
jQuery.fn.noisy = function(opacity) { | |
if (typeof(opacity) === 'undefined') { | |
opacity = 0.1; | |
} | |
var wrapper = jQuery(this).wrapInner('<div />').children(); | |
var canvas = document.createElement("canvas"); | |
canvas.width = 100; | |
canvas.height = 100; | |
var ctx = canvas.getContext("2d"); |
This file contains 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
define('REMEMBER_TIMEOUT',time()+60*60*24*2); | |
define('REMEMBER_SALT','secretword'); | |
define('REMEMBER_COOKIE','some_cookie_name'); | |
function remember_me($set=false, $username='') | |
{ | |
$db = mongo(); | |
// Set the cookie and add the db record | |
if($set) |
This file contains 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 | |
// Log to a file | |
function dump($data,$file='/var/log/mylog.log') | |
{ | |
file_put_contents($file, $data."\n", FILE_APPEND); | |
} | |
// Use some locking for a cron job | |
function lockit($name) | |
{ |