Skip to content

Instantly share code, notes, and snippets.

View jballanc's full-sized avatar

Joshua Ballanco jballanc

View GitHub Profile
;; warm up: balancing
=> (s/def ::balanced
(s/* (s/cat :open #{'<} :children ::balanced :close #{'>})))
:user/balanced
=> (s/conform ::balanced '[< < > < > > < >])
[{:open <, :children [{:open <, :close >} {:open <, :close >}], :close >} {:open <, :close >}]
=> (s/conform ::balanced '[< < > < < > > > < >])
[{:open <, :children [{:open <, :close >} {:open <, :children [{:open <, :close >}], :close >}], :close >} {:open <, :close >}]
;; infix to prefix
@DamienCassou
DamienCassou / configuration.nix
Created October 22, 2014 13:41
configuration.nix file for NixOS on my macbook pro
{ config, pkgs, ... }:
let
hostname = "luz3";
in {
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
# I use VirtualBox to connect to Windows and Linux guests
@robert-stuttaford
robert-stuttaford / datomic.clj
Last active April 27, 2018 15:10
Handy protocols for working with Datomic
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Connection
(defprotocol DatomicConnection
(as-conn [_]))
(extend-protocol DatomicConnection
datomic.Connection
(as-conn [c] c)
datomic.db.Db
@john2x
john2x / 00_destructuring.md
Last active April 10, 2024 19:12
Clojure Destructuring Tutorial and Cheat Sheet

Clojure Destructuring Tutorial and Cheat Sheet

(Related blog post)

Simply put, destructuring in Clojure is a way extract values from a datastructure and bind them to symbols, without having to explicitly traverse the datstructure. It allows for elegant and concise Clojure code.

Vectors and Sequences

@joshmoore
joshmoore / permissions.md
Last active August 29, 2015 13:58
OMERO Permissions

In-use

  • rw---- : private group (admin can read)
  • rwr--- : collab. read-only
  • rwra-- : collab. read-annotate

Currently proposed

  • r----- : and
@cgrand
cgrand / comprehensions.clj
Created May 24, 2013 14:06
Comprehension framework, upon which are (re)implemented, for, doseq, reducible/foldable for and reduce-based doseq
;; I wrote this in the Eurostar on my way back from the last lambdanext.eu clojure course.
(ns comprehensions
(:refer-clojure :exclude [for doseq])
(:require [clojure.core.reducers :as r]))
;; borrowed from clojure.core
(defmacro ^{:private true} assert-args
[& pairs]
`(do (when-not ~(first pairs)
@colinta
colinta / letmeexplain.md
Created May 7, 2013 15:49
Here's what I mean when I say "ReactiveCocoa is just a fancy word for: 'DSL'"

I don't want anyone to think that I am not a big fan of ReactiveCocoa. I'm a HUGE FAN of it!

But look how LONG it took for something like this to come about. Cocoa is an OLD OLD system, and even though KVO/KVC wasn't there at the birth, it has been there at least a decade. I pretty much gave up on Obj-C in favor of RubyMotion, and look at our landscape: Futuristic, ProMotion, Formotion, Geomotion, Elevate, Teacup - all of these projects bring expressiveness to Cocoa, and RubyMotion is barely a year old.

So what I meant to say is that Obj-C suffers from a lack of expressiveness - this has nothing to do with ReactiveCocoa, that's just my example. To illustrate my point, I will translate the first example of the ReactiveCocoa README. I encourage you to read the ReactiveCocoa source and try and consolidate all the code that is used to handle this function. I will include all of the Ruby code that is necessary for my translation to work.

I do have one qualm with ReactiveCocoa: the names. I'm going to t

@seanlilmateus
seanlilmateus / app_delegate.rb
Last active December 15, 2015 17:29
Countries example using Concurrency
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds).tap do |win|
win.rootViewController = UINavigationController.alloc.initWithRootViewController(CountriesController.new)
win.backgroundColor = UIColor.whiteColor
win.makeKeyAndVisible
end
true
@mrb
mrb / parse_ruby.clj
Last active December 14, 2015 17:29
Using JRuby's Ruby Parser from Clojure
(ns graaaph.core
(:import (org.jrubyparser Parser
CompatVersion)
(org.jrubyparser.parser ParserConfiguration)
(org.jrubyparser.ast Node)
(java.io.StringReader))
(:require [clojure.zip :as z]))
(defn parse-ruby [ruby-string]
(let [config (ParserConfiguration. 0 (CompatVersion/RUBY1_9))
@ferrous26
ferrous26 / bf.rb
Last active December 11, 2015 07:38
Brainfuck interpreter in Ruby
#!/usr/bin/env ruby
mem = Array.new(30_000)
iptr = dptr = 0
prog = File.read ARGV.first
jmp = lambda { |op, a, b|
(iptr = iptr.send(op, 1); jmp.call(op, a, b) if prog[iptr] == a) until prog[iptr] == b
}
nop = lambda {}
cmds = {
'>' => lambda { dptr += 1 },