Skip to content

Instantly share code, notes, and snippets.

View jszmajda's full-sized avatar

Jess Szmajda jszmajda

View GitHub Profile
@jszmajda
jszmajda / keybase.md
Created February 24, 2014 23:19
keybase.md

Keybase proof

I hereby claim:

  • I am joshsz on github.
  • I am joshsz (https://keybase.io/joshsz) on keybase.
  • I have a public key whose fingerprint is 3F4F 9FA1 5EAD 8A01 42B2 53C8 4C65 2781 7347 DB14

To claim this, I am signing this object:

@jszmajda
jszmajda / dot_notation.rb
Created July 22, 2014 23:54
Dot Notation
module DotNotation
def self.included(base)
raise "Unsupported Class" unless base.respond_to?('[]')
end
def dot(path)
return nil if self.nil? # optimization for NilClass
data = self
path.split(/\./).each do |selector|
@jszmajda
jszmajda / dot_notation.rb
Last active August 29, 2015 14:04
Dot Notation
# Simple-ish enumberable-simplifier. Useful for APIs like Twitter, etc
#
# If you have a hash or an array or something that quacks like one, you can do stuff
# example:
# h = {a: {b: {c: [{d: 'hi'}]}}}
# h.extend(DotNotation)
# h.dot('a.b.c.0.d')
# #=> 'hi'
# h.dot('a.b.c.foo.bar.bz.whatever.124.whocares')
# #=> nil
@jszmajda
jszmajda / 1.md
Last active August 29, 2015 14:05
Dumb haskell gloss example

Sometimes you just want a little plasma...

plasma

@jszmajda
jszmajda / printf.hs
Last active August 29, 2015 14:09
Text.Printf return type polymorphism example
Prelude> import Text.Printf
Prelude Text.Printf> printf "%0.2f\n" 3.14159 -- will write the line to STDOUT
3.14
Prelude Text.Printf> printf "%0.2f\n" 3.14159 :: String
"3.14\n"
Prelude Text.Printf> :t printf "%0.2f\n" 3.14159 :: IO ()
printf "%0.2f\n" 3.14159 :: IO () :: IO ()
Prelude Text.Printf> :t printf "%0.2f\n" 3.14159 :: String
printf "%0.2f\n" 3.14159 :: String :: String
module MongoMapper
module Associations
class InArrayProxy < Collection
def set_parent(parent, options={})
self.each do |k|
k.set_parent(parent)
if (!options.has_key?(:recursive) or options[:recursive] == true) and k.send( reflection.name ).size > 0
k.send( reflection.name ).set_parent(k, options)
end
end
# in lib/asset_tag_helper_ext.rb
module ActionView
module Helpers
module AssetTagHelper
alias :orig_javascript_include_tag :javascript_include_tag
def javascript_include_tag(*sources)
options = sources.extract_options!.stringify_keys
rkey = '__scripts'
request[rkey] ||= []
class Car
include MongoMapper::Document
key :make, String
key :_type, String
end
class Honda < Car
key :honda_thing, String
end
module FooHelper
include PartialMethods
end
gem 'ruby-terminfo'
require 'terminfo'
def syst(cmd)
sym = '-'
dist = ((TermInfo.screen_size[1].to_f/2.to_f) - ((cmd.length.to_f + 2.to_f) / 2.to_f)).floor.to_i
mid = cmd
#color = "7;93"
color = "93"
newlines = 4