Skip to content

Instantly share code, notes, and snippets.

View alyssais's full-sized avatar
🤒
Out sick

Alyssa Ross alyssais

🤒
Out sick
View GitHub Profile
@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 / 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 / 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 / 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 / async.rb
Created April 7, 2014 12:27
A Ruby implementation of a waterfall control flow thingy.
module Async
class << self
def waterfall(objects, handler, &block)
enumerator = objects.each
prev_result = nil
run_next = lambda do
begin
# onwards!
prev_result = handler.(enumerator.next, prev_result) do |success|
success ? run_next.call : block.(false)
@alyssais
alyssais / IIIAsync.podspec
Created April 10, 2014 17:03
A podspec for IIIAsync
Pod::Spec.new do |spec|
spec.name = 'IIIAsync'
spec.version = '0.2.0'
spec.license = { :type => 'MIT' }
spec.homepage = 'https://github.com/stevestreza/IIIAsync'
spec.authors = { 'Steve Streza' => '[email protected]' }
spec.summary = 'Concurrency control flow system for Objective-C'
spec.source = { :git => 'https://github.com/stevestreza/IIIAsync.git', :commit => '4e403e1a27542b7fa5defd49416d30930eb3b540' }
spec.source_files = 'IIIAsync/IIIAsync.{h,m}'
spec.requires_arc = true
@alyssais
alyssais / gist:61edce0ad8893575b293
Created May 3, 2014 21:56
Extracting an imported EPUB from iBooks for Mac
  1. Go to ~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books/
  2. Locate the folder for the book (the name will have been changed to a randomized string)
  3. Compress the folder into a .zip
  4. Change the .zip extension to .epub

And you thought iTunes was bad.

@alyssais
alyssais / jekyll.sh
Created May 3, 2014 22:23
Fixing Jekyll for @Januzellij
brew install rbenv ruby-build
echo "eval $(rbenv init -)" >> ~/.zshrc
source ~/.zshrc
rbenv install 2.1.1
rbenv global 2.1.1
gem install jekyll
rbenv rehash
@import "web-fonts";
@include web-fonts("Open Sans", "Droid Serif", "Pacifico");
#import "socket.h"