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 / split_array.rb
Created September 26, 2011 16:13
Split an array in to n approximately pieces.
# Split an array in to n approximately equal pieces.
#
# Example usage:
#
# ('a'..'f').to_a.split_in_to(3) => [["a", "b"], ["c", "d"], ["e", "f"]]
# (1..7).to_a.split_in_to(2) => [[1, 2, 3, 4], [5, 6, 7]]
class Array
def split_into(pieces = 2)
len = self.count
@noprompt
noprompt / derail.sh
Created February 15, 2012 23:32
Kill rails processes and a random number of passengers.
PROCESS_ID=`ps aux | grep rails | grep -v grep | cut -d ' ' -f3 | head -n 1`
if [[ -n "$PROCESS_ID" ]]
then
kill -9 $PROCESS_ID
echo "Derailing the train! $RANDOM passengers have died ..."
else
echo "No train in site."
fi
@noprompt
noprompt / gist:2961726
Created June 20, 2012 19:34
Hex color words!
ABACAS => #ABACA5
ABASED => #ABA5ED
ABASES => #ABA5E5
ABBESS => #ABBE55
ABODED => #AB0DED
ABODES => #AB0DE5
ACCEDE => #ACCEDE
ACCESS => #ACCE55
ADOBES => #AD0BE5
ADOBOS => #AD0B05
@noprompt
noprompt / SQL*.clj
Last active December 13, 2015 19:38
(defmacro SQL* [& clauses]
(let [query (walk/postwalk
(fn [x]
(if (and (symbol? x) (re-find #"^[A-Z]+$" (name x)))
(if (resolve x)
x
(str x))
x)) clauses)
query (cons 'list query)]
`(join \space ~query)))
@noprompt
noprompt / lorem-ipsum.clj
Last active March 10, 2017 14:50
Lorem Ipsum in Clojure. Pretty straight forward.
(ns lorem-ipsum
(:require [clojure.string :as string]))
(def lorem-ipsum
"Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?")
(def sentences
(string/split lorem-ipsum #"(?<=[.?]) "))
(defn random-sen
@noprompt
noprompt / migration.clj
Last active December 17, 2015 22:19
A naive database migration library for Korma.
(ns example.migration
(:require [example.table-util :as u]
[korma.core :as k]))
;; We need a table to help us keep track of the schema version so
;; whenever we migrate or rollback we know where we are before
;; executing any migration code.
;;
;; The `create-schema-migrations-table` function is called whenever a
;; migration or rollback is executed to make sure we have something to
@noprompt
noprompt / project.clj
Last active December 19, 2020 14:38
Demonstration using Garden to recreate the Semantic Grid framework.
(defproject semantic-gs "0.1.0-SNAPSHOT"
:dependencies [[org.clojure/clojure "1.5.1"]
[compojure "1.1.5"]
[garden "0.1.0-beta5"]
[hiccup "1.0.3"]]
:plugins [[lein-ring "0.8.5"]]
:ring {:handler semantic-gs.handler/app}
:profiles
{:dev {:dependencies [[ring-mock "0.1.5"]]}})
@noprompt
noprompt / cypher-dsl.clj
Last active March 24, 2023 15:57
A Clojure Cypher query DSL compatible with neocons.
(ns noprompt.cypher
(:require [clojure.string :as str]
[clojurewerkz.neocons.rest.cypher :as cy]
[clojure.walk :as walk])
(:import java.lang.StringBuilder))
;; Example usage:
(comment
;; Query:
(start {:n (node [3 1])}
@noprompt
noprompt / word-re.txt
Last active May 2, 2016 15:30
Regular expression for matching any word in `/usr/share/dict/words`.
This file has been truncated, but you can view the full file.
(?:s(?:(?:u(?:b(?:(?:s(?:t(?:a(?:n(?:t(?:i(?:a(?:l(?:(?:i(?:s[mt]|a|ty|ze)|ly|ness))?|t(?:i(?:on|ve)|e|or)|bility)|v(?:e(?:(?:ly|ness))?|al(?:ly)?|i(?:ty|ze))|fy|ous|ze))?|c(?:e(?:less)?|h)|dard(?:ize)?)|lagmit(?:e|ic)|ge|tion)|r(?:a(?:t(?:o(?:s(?:pher(?:e|ic)|e)|r)|i(?:ve)?|al|e|um)|ct(?:ion)?)|uct(?:(?:ion(?:al)?|ur(?:al|e)))?|iate)|itu(?:t(?:i(?:on(?:a(?:l(?:ly)?|ry))?|ng(?:ly)?|ve(?:ly)?)|e(?:[dr])?|able)|ent)|o(?:r(?:eroom|y)|ck)|yl(?:ar|e)|ernal)|e(?:[ta]|r(?:v(?:i(?:en(?:t(?:(?:ly|ness))?|c[ey])|ate)|e)|o(?:sa|us)|ies|rate)|c(?:u(?:t(?:e|ive)|rity)|retar(?:ial|y)|t(?:ion)?|ive)|quen(?:t(?:(?:ial(?:ly)?|ly|ness))?|c[ey])|ns(?:u(?:al|ous)|ation|ible)|pt(?:uple)?|mi(?:fusa|tone)|xtuple|wer|ssile|gment)|i(?:d(?:i(?:ar(?:i(?:e|ly|ness)|y)|z(?:a(?:ble|tion)|e(?:r)?)|ng|st)|e(?:(?:n(?:c[ey]|t)|r))?|y)|st(?:(?:en(?:c[ey]|t(?:ial)?)|ingly))?|l(?:ic(?:ate|ic)|l)|m(?:i(?:lation|ous)|ple)|zar(?:ship)?|nuous)|c(?:ri(?:pt(?:(?:i(?:on(?:ist)?|ve(?:ly)?)|ure))?|b(?:e(?:r(?:ship)?)?|able)|ve(?:r)?)|apular(?:(?:is|y))?|
@noprompt
noprompt / console-macros.clj
Last active December 22, 2015 05:59
ClojureScript console functions/macros
(ns clojurescript.console.macros
(:refer-clojure :exclude [time]))
(defmacro with-group [title & body]
`(do
(.group js/console ~title)
~@body
(.groupEnd js/console)))
(defmacro with-group-collpased [title & body]