Skip to content

Instantly share code, notes, and snippets.

View nporteschaikin's full-sized avatar

Noah Portes Chaikin nporteschaikin

View GitHub Profile
@nporteschaikin
nporteschaikin / twitter.php
Last active December 11, 2015 03:38
PHP code to grab and cache Twitter
<?php
function twitter ( $username, $file = 'twitter.xml', $interval = 600 ) {
$url = 'https://api.twitter.com/1/statuses/user_timeline/' . $username . '.xml?count=3';
if ( ( is_file ( $file ) && ( time () - filemtime ( $file ) ) > $interval ) || filesize ( $file ) == 0 ) {
$curl = curl_init();
curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt ( $curl, CURLOPT_URL, $url );
@nporteschaikin
nporteschaikin / prototypes.js
Last active December 21, 2015 00:59
Some useful extensions from JavaScript and jQuery.
// Array.matches: find all matches between two arrays
// usage: arr1.matches(arr2);
Array.prototype.matches=function(a){var m=[];for(i=0;i<this.length;i++){if(a.indexOf(this[i])>-1){m.push(this[i])}}return m;}
// jQuery.collectValues: collect all values in selected inputs
// usage: $('input, textarea').collectValues();
jQuery.prototype.collectValues=function(){var a=[];this.each(function(){a.push($(this).val())});return a;}
@nporteschaikin
nporteschaikin / application_helper.rb
Last active December 28, 2015 04:09
Hierarchical navigation in Rails. This assumes your routes are hierarchical, too.
def nav_parent(options = {}, &block)
content_tag :ul, capture(&block), options
end
def nav_link_to(name, route, options = {}, &block)
options[:class] ||= "active" if current_page?(route) || request.env["PATH_INFO"].starts_with?(route)
content_tag :li, (link_to(name, route) + (content_tag(:ul, capture(&block)) if block_given?)), options
end
def pluralize_bottle(num);if num == 1;"#{num} bottle";else;"#{num} bottles";end;end;x = 99;while(x > 0) do; puts("#{pluralize_bottle(x)} of beer on the wall!"); sleep(1); puts("#{pluralize_bottle(x)} of beer!"); sleep(1); puts("You take one down..."); sleep(1); puts("Pass it around..."); sleep(1); x-=1; puts "#{pluralize_bottle(x)} of beer on the wall!";sleep(2);if(x==0);puts("No more bottles of beer on the wall, no more bottles of beer. Go to the store and buy some more, 99 bottles of beer on the wall.");4.times do;sleep(2);puts("...");sleep(2);end;x=99;else;puts("...");end;sleep(2);end
@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) {
#!/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 / 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;
}
@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 / 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 / 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.