Skip to content

Instantly share code, notes, and snippets.

View jszmajda's full-sized avatar

Jess Szmajda jszmajda

View GitHub Profile
@jszmajda
jszmajda / wordwrap.hs
Created February 4, 2016 13:53
Polyglot Programming DC Randori of WordWrap function
wordWrap :: String -> Int -> String
wordWrap xs maxLineLength = wordWrapHelper "" xs maxLineLength maxLineLength
wordWrapHelper :: String -> String -> Int -> Int -> String
wordWrapHelper result xs maxLineLength index
| length xs < maxLineLength + 1 = result ++ xs
| xs !! index == ' ' = wordWrapHelper (result ++ firstPart) lastPart maxLineLength maxLineLength
| otherwise = wordWrapHelper result xs maxLineLength (index - 1)
where
firstPart = (take index xs) ++ "\n"
@jszmajda
jszmajda / CodesOfConductAreHard.md
Last active January 26, 2016 02:55
This is a simplification of https://subfictional.com/2016/01/25/the-complex-reality-of-adopting-a-meaningful-code-of-conduct/ The goal is to share the knowledge in this article in simple, short language. If you have time, please read the original.
@jszmajda
jszmajda / gist:300ca553bf3e4fe3ff2d
Last active October 20, 2015 13:50
libv8 osx 10.11 woes
> brew uninstall v8
Uninstalling /usr/local/Cellar/v8/4.5.103.35... (25 files, 29M)
> brew uninstall v8-315
Uninstalling /usr/local/Cellar/v8-315/3.15.11.18... (21 files, 18M)
> gem uninstall libv8
Successfully uninstalled libv8-4.5.95.5
> gem uninstall therubyracer
> brew install v8-315
==> Installing v8-315 from homebrew/homebrew-versions
==> Downloading https://homebrew.bintray.com/bottles-versions/v8-315-3.15.11.18.el_capitan.bottle.1.tar.gz
# Multiple inheritance with Modules as an alternative to injected composition
# from Sandi Metz's talk [Nothing is Something](http://confreaks.tv/videos/bathruby2015-nothing-is-something)
# Like Sandi's 'direct' DI method this has behavior outside of the base class
# that gets composed together. However in this gist I compose modules in class
# definitions instead of injecting collaborators.
# Tradeoffs between this and Sandi's version are that in this case the API consumer doesn't
# have to know how to make a RandomEchoHouse (no `house = House.new(formatter: Whatever.new)`),
# but also the API consumer can't make anything not already accounted for either.
@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
@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 / 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 / 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 / 1readme.md
Last active September 3, 2022 18:33
Data Serialization: JSON, MsgPack, ProtoBufs
@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: