Skip to content

Instantly share code, notes, and snippets.

View prestonp's full-sized avatar
😍
you had me at hello world

Preston Pham prestonp

😍
you had me at hello world
View GitHub Profile
  • Poll schema uses string for results, how could we improve on this? Also the following request allows me to completely change the results
curl -H 'Content-Type: application/json' -X PUT -d '{ "results":  ["32", "2", "5", "0"] }' http://localhost:9000/api/polls/556c8129bf64e30727806aeb
  • socket io is used but the poll is updated not real time. Suppose I vote and leave the tab open with the results. The results should get updated as others are voting. What steps would be taken in order to push updates?
  • Were there any challenges in putting the project together?
  • What would you change or improve on? What other things would you like to work on if you had more time?
@prestonp
prestonp / macros.md
Last active August 29, 2015 14:22
summer macros
Carbs Protein Fat Fiber Calories
Grams per day 335.7 135 47.3 27-34 2308
Grams per meal 111.9 45 15.8 9-11 769

For 3 meals/day at 135lbs for a surplus of ~200 cals

http://iifym.com/iifym-calculator/

BMR = 1,524 Calories/day

@prestonp
prestonp / base62.js
Created May 21, 2015 23:09
uuids in base 62
// just gluing libs
var uuid = require('node-uuid')
var Base62 = require('base62')
var genUUID62 = function() {
var buffer = [];
var opts = null;
var offset = 0;
uuid.v4(opts, buffer, offset);
@prestonp
prestonp / incremental.md
Last active August 29, 2015 14:19
progressive rendering

In many websites, there are static portions of the page such as the navigation or header that rarely change. If we could deliver the markup for navigation, the experience would feel a bit snappier while the rest of the page is generated.

Try running this snippet in node and visit localhost:3000/incremental and localhost:3000/blocking. These are pretty trivial examples but we could cache and immediately send the nagivation bar and `` elements for every request.

@prestonp
prestonp / ex.md
Created April 19, 2015 03:49
mal tco factorial
// not tail call optimized
(def! fact (fn* (x) (if (= x 0) 1 (* x (fact (- x 1) )) )))

// tail call opt
(def! fact-tail (fn* [x accum] (if (= x 0) accum (fact-tail (- x 1) (* x accum)))))
(def! fact (fn* [x] (fact-tail x 1)) )

No formatting because... newlines mess up interpreter parsing.

Keybase proof

I hereby claim:

  • I am prestonp on github.
  • I am preston (https://keybase.io/preston) on keybase.
  • I have a public key whose fingerprint is 60DB 9188 6664 3B9C 4991 62C8 D02C 5B5A AC8C C409

To claim this, I am signing this object:

@prestonp
prestonp / requirejs.md
Created April 1, 2015 17:05
requirejs

AMD asynchronous module definition

Defining a new module

define('Robot', ['jquery'], function($) {
  return function Robot() {
  };
});
@prestonp
prestonp / gist:4f249bf23a273759afec
Created March 9, 2015 22:36
grab iso weeks from month
select extract(week from n) from generate_series('2015-02-01'::timestamp, '2015-02-28', '1 week') n;
@prestonp
prestonp / count-by.js
Created February 27, 2015 23:04
Count By
// count # of any object property
var getProperty = function( obj, prop ) {
if (prop.indexOf('.') < 0) return obj[prop];
var parts = prop.split('.')
, last = parts.pop()
, len = parts.length
, idx = 1
, current = parts[0];
while( (obj = obj[current]) && idx < len ) {
@prestonp
prestonp / gist:9ed46564b95180c8837d
Last active August 29, 2015 14:08
check if a row exists

Postgres exists(EXPRESSION) so useful

select *, exists(select 1 from order_amenities where order_id = 4275) as checked from amenities where restaurant_id = 187;