Skip to content

Instantly share code, notes, and snippets.

View nporteschaikin's full-sized avatar

Noah Portes Chaikin nporteschaikin

View GitHub Profile
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 / 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
@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 / 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 );