Skip to content

Instantly share code, notes, and snippets.

View alyssais's full-sized avatar

Alyssa Ross alyssais

View GitHub Profile
@alyssais
alyssais / yaml.rb
Last active August 29, 2015 13:57
Make motion-yaml retain original YAML if object being re-serialized has not been modified.
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
@alyssais
alyssais / main.rb
Last active January 2, 2016 21:29
This is going to make @matthewmascioni cry.
Teacup::Stylesheet.new :main do
style :fill,
constraints: [
:full_width,
:full_height
]
style :entry,
constraints: [
@alyssais
alyssais / handlebars.rb
Created December 28, 2013 17:15
A Handlebars template handler for Rails.
$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)))]
@alyssais
alyssais / associations.rb
Last active January 1, 2016 14:49
Convert an ActiveRecord model into a hash structure with all associations.
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
@alyssais
alyssais / leaderboard.js
Last active April 19, 2024 02:26
A script to calculate a leaderboard for Node Knockout 2013.
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;
@alyssais
alyssais / gist:7398998
Created November 10, 2013 14:35
HELLO!
THIS IS FUN
@alyssais
alyssais / randomusers.js
Created October 1, 2013 12:57
Gets lots of users from randomiser.me.
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) {
@alyssais
alyssais / TVC.m
Created September 22, 2013 14:48
My (probably wrong) way of doing dynamic height UITableViewCells.
- (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;
@alyssais
alyssais / iTunes.rb
Created May 15, 2013 20:12
Calculates the time that Apple will reach 50 billion apps.
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
@alyssais
alyssais / UIBarButtonItem+CustomButton.h
Created May 11, 2013 10:19
Makes it easier to use custom UIButtons for the crappy UIBarButtonItems in a bar.
//
// UIBarButtonItem+CustomButton.h
//
// Created by Ross Penman on 11/05/2013.
// Copyright (c) 2013 Ross Penman. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface UIBarButtonItem (CustomButton)