Skip to content

Instantly share code, notes, and snippets.

View noprompt's full-sized avatar
💭
The choice to have discipline is a programmer's worst enemy.

Joel Holdbrooks noprompt

💭
The choice to have discipline is a programmer's worst enemy.
View GitHub Profile
@noprompt
noprompt / conditionally-run-ruby.el
Last active May 13, 2016 21:40
Emacs helper to conditionally run `irb`, `pry`, `bundle console`, or `rails console` with respect to the current working directory.
(when (not (boundp 'inf-ruby-implementations))
(setq inf-ruby-implementations nil))
(defun ~/paths-to-root (file-name)
(let* ((path-parts (s-split "/" (file-name-directory file-name) t))
(build-path (lambda (path-parts)
(concat "/" (s-join "/" path-parts))))
(paths (reduce (lambda (state _)
(let* ((old-path-parts (cdr state))
(new-path-parts (-butlast old-path-parts))
# @return [Array<String>]
def gem_paths
Gem.path.flat_map { |path| Dir.glob("#{path}/gems/*") }
end
# @param [String] gem_name
# @return [Boolean]
# @raise [LoadError]
def require_gem(gem_name)
if defined?(::Bundler)
@noprompt
noprompt / walk.rb
Last active February 18, 2016 21:01
Port of clojure.walk to Ruby
module Walk
refine Array do
def walk(inner_f, outer_f)
outer_f.(self.map(&inner_f))
end
end
refine Hash do
def walk(inner_f, outer_f)
@noprompt
noprompt / saturn.clj
Last active March 9, 2016 00:01
Somewhere between multimethods and pattern matching lies Saturn.
(ns saturn)
;; ---------------------------------------------------------------------
;; Signature parsing
(defprotocol IParse
(-parse [x]))
(extend-protocol IParse
module Json.Decode.Generic where
import Json.Decode as Decode exposing (Decoder, (:=))
import Array exposing (Array)
import Dict exposing (Dict)
type JsonValue = JsonNull
| JsonBool Bool
| JsonString String
| JsonFloat Float
@noprompt
noprompt / organize.hs
Created November 28, 2015 17:54
My first Haskell script (organizes files in a directory by extension)
module Main where
import qualified System.Directory as Directory
import qualified System.FilePath as FilePath
import Control.Monad (forM, forM_, liftM)
import qualified Data.HashMap.Strict as HashMap
import Text.Printf (printf)
isFile :: FilePath -> IO Bool
isFile = Directory.doesFileExist
(letfn [(variadic? [arglist]
(boolean (some #{'&} arglist)))
(arglistc [arglist]
(if (variadic? arglist)
Double/POSITIVE_INFINITY
(count arglist)))
(partial-arglists [arglists argc]
(drop-while
@noprompt
noprompt / sablono-interpreter-atom.cljs
Last active August 29, 2015 14:21
Example demonstrating an implementation of `sablono.interpreter.IInterpreter` for `Atom`
(ns sablono.impl.atom
(:require
[sablono.interpreter]))
(extend-protocol sablono.interpreter/IInterpreter
Atom
(interpret [this]
(let [;; Watch key for the component observing `this` atom.
watch-key (gensym)]
(js/React.createElement
(deftype Chain [f args]
clojure.lang.IDeref
(deref [this]
(apply f (for [arg args]
(if (instance? Chain arg)
@arg
arg))))
clojure.lang.IFn
(invoke [this] this)
(defn has-method?
"True if multi-fn has a method for a dispatch-val."
[multi-fn dispatch-val]
(if-let [method (get-method multi-fn dispatch-val)]
(if-let [default-method (.-default-dispatch-val multi-fn)]
(not= method default-method)
true)
false))