Skip to content

Instantly share code, notes, and snippets.

View emidln's full-sized avatar

Brandon Adams emidln

  • Chicago, IL
View GitHub Profile
@AlexBaranosky
AlexBaranosky / defmatch.clj
Created October 3, 2011 01:53
macro to define match-based functions
(ns playmatch
(:use [clojure.core.match.core :only (match)]))
(defn len [coll]
"calc the length of a sequence"
(match [coll]
[[]] 0
[[f & r]] (inc (len r))))
@jsmorph
jsmorph / logicrels-lucene.clj
Created July 6, 2012 14:01
Lucenalog: Datalog interface to Lucene in 10 lines
(ns lucenalog.core
"Lucenalog = Datalog interface to Lucene in 10 lines.
Simple but powerful.
Use
(db/add (index) {:a \"foo\" :b \"bar\"})
to index a map with Lucene. Then you can use the relation
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active November 17, 2024 13:10
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@carletes
carletes / ubuntu-kernel-for-acer-c7.sh
Last active November 22, 2018 03:51
Script to create Ubuntu kernel packages for an Acer C7 Chromebook running ChrUbuntu
#!/bin/bash
set -x
#
# Grab verified boot utilities from ChromeOS.
#
mkdir -p /usr/share/vboot
mount -o ro /dev/sda3 /mnt
cp /mnt/usr/bin/vbutil_* /usr/bin
@mrflip
mrflip / tuning_storm_trident.asciidoc
Last active October 8, 2024 15:18
Notes on Storm+Trident tuning

Tuning Storm+Trident

Tuning a dataflow system is easy:

The First Rule of Dataflow Tuning:
* Ensure each stage is always ready to accept records, and
* Deliver each processed record promptly to its destination
@halgari
halgari / gist:7160778
Created October 25, 2013 19:47
Using core.logic to query custom data sources.
(ns extend-core-logic.core
(:require [clojure.core.logic :refer :all]
[clojure.core.logic.protocols :refer [walk]]
[clojure.java.io :as jio]
[clojure.string :as string])
(:import [java.io BufferedReader StringReader]))
;; from: http://federalgovernmentzipcodes.us/
(defn load-db []
(let [data (java.io.BufferedReader. (java.io.StringReader. (slurp "/Users/tim/Downloads/free-zipcode-database.csv")))
@svard
svard / redis-state
Created April 27, 2014 20:33
Trident redis state using marceline
;; Trident state persisted in redis.
;; Implemented in clojure using marceline lib.
;; Based on https://github.com/kstyrc/trident-redis
(ns state.redis
(:require [marceline.storm.trident :as t]
[clj-redis.client :as redis])
(:import [storm.trident.state.map CachedMap TransactionalMap NonTransactionalMap OpaqueMap SnapshottableMap]))
(defn- get-type-map
@ghadishayban
ghadishayban / weighted_rand.clj
Last active September 23, 2022 08:15
Vose's alias method for weighted randoms
(ns weighted-rand
(:import clojure.lang.PersistentQueue))
(defprotocol Rand
(nextr [_ rng]))
;; Vose's alias method
;; http://www.keithschwarz.com/darts-dice-coins/
(deftype Vose [n ^ints alias ^doubles prob]
@MichaelDrogalis
MichaelDrogalis / gist:bc620a7617396704125b
Last active May 22, 2018 14:26
The Anatomy of an Onyx Program

The Anatomy of an Onyx Program

In this tutorial, we'll take an in-depth view of what's happening when you execute a simple Onyx program. All of the code can be found in the Onyx Starter repository if you'd like to follow along. The code uses the development environment with HornetQ and ZooKeeper running in memory, so you don't need additional dependencies to run the example for yourself on your machine.

The Workflow

At the core of the program is the workflow - the flow of data that we ingest, apply transformations to, and send to an output for storage. In this program, we're going to ingest some sentences from an input source, split the sentence into individual words, play with capitalization, and add a suffix. Finally, we'll send the transformed data to an output source.

Let's examine the workflow pictorially:

;; extend honeysql
(defmethod honeyhelpers/build-clause :returning [ _ m cols]
(assoc m :returning (honeyhelpers/collify cols)))
(defmethod honeyfmt/format-clause :returning [[_ cols] _]
(str "RETURNING " (honeyfmt/comma-join (map honeyfmt/to-sql cols))))
(extend-protocol honeyfmt/ToSql
clojure.lang.Sequential