Skip to content

Instantly share code, notes, and snippets.

View TJkrusinski's full-sized avatar

TJ Krusinski TJkrusinski

  • Facebook
  • Menlo Park, CA
View GitHub Profile
@TJkrusinski
TJkrusinski / distance.js
Created April 4, 2017 22:22
Average distance of two random points in a square with side length 1
function compute() {
return distance(points());
}
function distance(points) {
var deltaY = points[3] - points[1];
var deltaX = points[2] - points[0];
return Math.sqrt(Math.pow(deltaY, 2) + Math.pow(deltaX, 2));
}
// contrived example
$box-height: 30px;
$box-width: 30px;
// optional args
@mixin box-me-bro ($width: $box-width, $height: $box-height) {
var err = {
message: 'You are a human, here is the error',
exception: new Error('this is for the system')
};
@TJkrusinski
TJkrusinski / equal.js
Created July 16, 2014 17:30
equality yum yums
var a = Object.create(null);
a.toString = function() {
return 4;
};
a == 4;
// truthy!
typeof a == typeof 4;
@TJkrusinski
TJkrusinski / prototype.md
Last active August 29, 2015 14:03
Prototype Talk

Prototype

  • Inheritence in general
  • Prototypal vs clasical inheritence
  • Constructors in javascript vs literals
  • Primitive types and what it means to 'extend' their prototypes
  • Creating constructors
  • Initializing contstructors with the new keyword and what the value of this is
  • Extending classes with Object.create

amazon npm

Amazon S3 now supports versioning on objects. This means you can send new versions of objects to S3 and they persist older verions. The version numbers are arbitraty strings, so semantic versioning would work just fine. Potentially you could have a client application that allows you to store private npm packages on s3. If the package 404s, then you can fallback to the main npm registry. This is effectively a quick and dirty private npm.

My question is, what am I missing? Is there more to npm that versioned s3 objects can provide?

find ./views -type f -name \*.jade | while IFS="" read i; do expand -t2 "$i" > "$i-"; mv "$i-" "$i"; done
/**
* Self constructing constructor?
*/
function Dog (props) {
if (!(this instanceof Dog)) return new Dog(props);
this.props = props || {};
};
Dog.prototype.bark = function () {
@TJkrusinski
TJkrusinski / fs.js
Created April 28, 2014 15:40
Foursquare example
'use strict';
var key = 'your client key';
var secret = 'your secret key';
var fs = require('node-foursquare-venues')(key, secret);
function getHours(venue, callback) {
fs.venues.venue(venue, function(err, data){
if (err) return callback(err, null);
'use strict';
/**
* Typical constructor
*/
function Human (props) {
this.props = props || {};
};