This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class << YAML | |
| alias _load load | |
| private :_load | |
| def load(yaml) | |
| hash = _load(yaml) | |
| unless hash.nil? | |
| hash.instance_variable_set(:@original_yaml, yaml) | |
| hash.instance_variable_set(:@original_parsed_yaml, hash) | |
| end | |
| hash |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Teacup::Stylesheet.new :main do | |
| style :fill, | |
| constraints: [ | |
| :full_width, | |
| :full_height | |
| ] | |
| style :entry, | |
| constraints: [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $handlebars = Handlebars::Context.new | |
| module HandlebarsTemplateHandler | |
| def self.call(template) | |
| if template.locals.include? "raw" | |
| "#{template.source.inspect}.html_safe" | |
| else | |
| %{ | |
| locals = #{template.locals.inspect} | |
| vars = Hash[locals.zip(locals.map(&method(:eval)))] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ActiveRecord::Base | |
| def self.associations(exclude = []) | |
| classes = Hash[reflect_on_all_associations.map do |association| | |
| if (association.klass rescue nil) | |
| association.as_json.values_at("name", "klass") | |
| end | |
| end.compact] | |
| Hash[classes.map do |assoc_name, klass| | |
| assocs = nil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var async = require("async"), | |
| request = require("request"), | |
| _ = require("lodash"), | |
| cheerio = require("cheerio"); | |
| var get = function(url, callback) { | |
| request(url, function(error, response, body) { | |
| if (error) { | |
| console.error(error); | |
| return; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| THIS IS FUN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var request = require("request"); | |
| var _ = require("underscore"); | |
| var fs = require("fs"); | |
| var usernames = []; | |
| var REQS = 100; | |
| for (var i = 0; i < REQS; i++) { | |
| request("http://api.randomuser.me?results=5", function(response, error, body) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath | |
| { | |
| CGFloat TEXT_VIEW_MARGIN_X = 14; // gap between edge of cell and edge of text view | |
| CGFloat TEXT_VIEW_INSET_X = 5; // gap between edge of text view and text inside | |
| CGFloat TEXT_VIEW_INSET_Y = 9; // gap between top/bottom of text view and text inside | |
| NSString *text = [self lorem]; | |
| CGSize constraint = CGSizeMake(tableView.bounds.size.width - (TEXT_VIEW_MARGIN_X + TEXT_VIEW_INSET_X) * 2, CGFLOAT_MAX); | |
| CGSize size = [text boundingRectWithSize:constraint options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:17]} context:nil].size; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'net/http' | |
| require 'json' | |
| puts "" | |
| MAX = 50 * 10 ** 9 # 50 billion | |
| # Get the URL of the JSON in case Apple changes it. | |
| url = URI.parse 'http://images.apple.com/v/itunes/shared/counter/a/scripts/counter.js' | |
| req = Net::HTTP::Get.new url.path |