View Mongo
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
// Adding a user auth to a DB (read/write, add true as a third param for read-only) | |
use somedb | |
db.addUser("username","pasword") | |
// Update an entry (don't forget $set or it will be replace only with what is provided) | |
db.gadgets.update({key:"Some criteria"},{$set:{weight:17.6}}) | |
// Dump a database/collection | |
mongodump -d databasename -c collection -o . |
View common.php
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) | |
{ |
View rememberme.php
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) |
View jquery.background-noise.js
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"); |
View androidTest.java
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(){ |
View DB.java
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; |
View cron.coffee
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', () -> |
View dataMap.js
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'} |
View binarySearch.js
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]); |
View fizzBuzz.js
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)+', '; | |
} |
OlderNewer