Skip to content

Instantly share code, notes, and snippets.

View nporteschaikin's full-sized avatar

Noah Portes Chaikin nporteschaikin

View GitHub Profile
function shuffle(array) {
for (var i=array.length-1; i>0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var temp = array[i];
array[i] = array[j];
array[j] = temp;
}
return array;
}
@nporteschaikin
nporteschaikin / events.js
Last active August 29, 2015 14:23
A tiny event emitter
!function(){var a=function(){};a.prototype={on:function(a,b){return this.events||(this.events={}),this.events[a]||(this.events[a]=[]),this.events[a].push(b),this},off:function(a,b){return(this.events||{})[a]&&(b?this.events[a].splice(this.events[a].indexOf(b),1):this.events[a]=[]),this},emit:function(a){if((this.events||{})[a])for(var b=0;b<this.events[a].length;b++)(this.events[a][b]||function(){}).apply(this,Array.prototype.slice.call(arguments,1));return this}},"function"==typeof define&&define.amd?define(a):"object"==typeof exports?module.exports=a:window.Emitter=a}();
@nporteschaikin
nporteschaikin / plus.less
Created June 12, 2015 12:20
Plus sign with LESS
.plus {
width: 20px;
height: 20px;
position: relative;
&:before,
&:after {
content: "";
position: absolute;
background: #000;

HTML:

<div id="foo">
  <div>
  </div>
</div>

CSS:

@nporteschaikin
nporteschaikin / Objective-C notes.md
Last active August 29, 2015 14:19
Objective-C notes

Obj-C/iOS dev notes

  • Use NS_DESIGNATED_INITIALIZER for designated initializers in header (>= iOS 8)

    // foo.h
    - (id)initWithFoo:(NSString *)foo NS_DESIGNATED_INITIALIZER;  
  • Use copy on NSString and `NSArray1 properties; (obviously) does not modify string at original pointer.

@nporteschaikin
nporteschaikin / gist:c6a920478b500c021dbe
Last active August 29, 2015 14:14
Simple animate-with-scroll JS lib
(function (root) {
function __() {
var Animations = {
backgroundColor: function (pct, fromValue, toValue) {
return {
property: 'background',
value: colorAnimation(pct, fromValue, toValue)
@nporteschaikin
nporteschaikin / NSInternalInconsistencyException.md
Last active January 16, 2016 11:30
NSInternalInconsistencyException

NSInternalInconsistencyException

Intermittently, Parse throws an exception when [[PFInstallation currentInstallation] addUniqueObject:forKey:] is called:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Operation is invalid after previous operation.'

References

@nporteschaikin
nporteschaikin / dateToZodiac.js
Last active July 13, 2023 11:53
Convert a Date object to the Zodiac sign it falls under.
function dateToZodiac(date) {
x = (date.getMonth() * 100) + date.getDate();
return x >= 221 && x <= 319 ? 'Aries' : x >= 320 && x <= 420 ? 'Taurus' : x >= 421 && x <= 520 ? 'Gemini' : x >= 521 && x <= 622 ? 'Cancer' : x >= 623 && x <= 722 ? 'Leo' : x >= 723 && x <= 922 ? 'Virgo' : x >= 823 && x <= 922 ? 'Libra' : x >= 923 && x <= 1021 ? 'Scorpio' : x >= 1022 && x <= 1121 ? 'Sagittarius' : x >= 1122 && x <= 19 ? 'Capricorn' : x >= 20 && x <= 118 ? 'Aquarius' : x >= 119 && x <= 220 ? 'Pisces' : void 0;
}
#!/bin/usr/env python
import httplib, mimetypes, mimetools, urllib2, cookielib, urllib
from multipart import Multipart
import re
import os
class RedirectHandler(urllib2.HTTPRedirectHandler):
def http_error_302(self,req,fp,code,msg,headers):
result = urllib2.HTTPRedirectHandler.http_error_302(
self, req, fp, code, msg, headers)
@nporteschaikin
nporteschaikin / keystr.js
Last active August 29, 2015 14:00
String of keys and values ---> Object
/*
* Returns an un-evaluated object from keys and values.
* @param {String} str - a string of keys and values separated by commas,
*
* Example:
* keyStr('firstname: "Noah", lastname: "Portes Chaikin", address: address_var');
* => Object {firstname: ""Noah"", lastname: ""PortesChaikin"", address: "address_var"}
*/
function keyStr(str) {