Skip to content

Instantly share code, notes, and snippets.

View akilism's full-sized avatar
💭
clicky-clicky-clicky

Akil Harris akilism

💭
clicky-clicky-clicky
View GitHub Profile
@akilism
akilism / promise-upsert
Last active August 29, 2015 13:56
Using Node, Q, and mongodb save an array of objects to a mongo collection.
var saveObjects = function (objects) {
var MongoC = MongoClient;
var mongoConnect = Q.nbind(MongoC.connect, MongoC);
return mongoConnect(dbString).then(function (db) {
var DocumentCollection = db.collection('collection');
var documentCollectionUpsert = Q.nbind(DocumentCollection.update, DocumentCollection);
//Use upsert option.
var options = { 'upsert' : true };
var upsertPromises = objects.map(function (obj) {
@akilism
akilism / promise-upsert-with-a-write-concern
Last active August 29, 2015 13:56
Node, Q, MongoDB - Upsert an array of objects with a write concern using Q.
var saveObjects = function (objects) {
var MongoC = MongoClient;
var mongoConnect = Q.nbind(MongoC.connect, MongoC);
return mongoConnect(dbString).then(function (db) {
var DocumentCollection = db.collection('collection');
var documentCollectionUpsert = Q.nbind(DocumentCollection.update, DocumentCollection);
//Use upsert option.
var options = { 'w' : 1, 'upsert' : true };
var upsertPromises = objects.map(function (obj) {

Keybase proof

I hereby claim:

  • I am akilism on github.
  • I am akilism (https://keybase.io/akilism) on keybase.
  • I have a public key whose fingerprint is 0C83 8B6E F921 49F3 A2BB B2DD D06C 0BC7 690A 958B

To claim this, I am signing this object:

@akilism
akilism / quicksort.js
Created March 20, 2015 04:25
quicksort js
var quickSort = (function(){
var items;
var less = function(a, b) { return compare(items[a], items[b]) < 0; };
var sort = function(items, lo, high) {
if(high <= lo) { return; }
mid = partition(items, high, lo);
sort(items, lo, mid-1);
sort(items, mid+1, high);
@akilism
akilism / MinPQ-es6.js
Last active May 8, 2017 20:46
Minimum Priority Queue ES6 Class syntax.
class MinPQ {
constructor(comparator) {
this.comparator = comparator || MinPQ.compare;
this.items = [];
this.n = 0;
}
insert(value) {
this.items[++this.n] = value;
this.swim(this.n);
@akilism
akilism / cnvs.js
Last active August 29, 2015 14:17
my tiny canvas starter
var cnvs = (function() {
var canvas,
ctx,
isCanvasEnabled,
drawPending,
canvasHeight,
canvasWidth,
time = 0,
counter = 0,
c,
@akilism
akilism / gist:b7bcc957a175c5d1b725
Created April 16, 2015 02:42
lua vectors for pico8
--begin vector functions
function addv(v1, v2)
return {x=v1.x+v2.x, y=v1.y+v2.y}
end
function subv(v1,v2)
return {x=v1.x-v2.x, y=v1.y-v2.y}
end
function multv(v,n)
@akilism
akilism / gist:7516adc88391965cc413
Last active August 29, 2015 14:19
some common functions for pico8
--some helpers
function rndint(x)
return flr(rnd(x))
end
function dir()
if randint(2) == 1 then
return 1
else
return -1
@akilism
akilism / gist:dfee322bb3a87f6cb635
Created April 16, 2015 02:44
add force and update
function updtm(m)
--if flr(m.pos.y) >= 127 then
-- m.pos.y = 127
-- return l
--end
m.vel = addv(m.vel, m.acc)
m.ang = addv(m.ang, m.vel)
m.pos = addv(m.pos, m.vel)
m.acc = multv(m.acc, 0)
@akilism
akilism / blend modes
Last active September 20, 2015 02:57
normal
multiply
screen
overlay
darken
lighten
color-dodge
color-burn
hard-light
soft-light