Skip to content

Instantly share code, notes, and snippets.

@gdbassett
gdbassett / bulk_netflow_import.py
Created November 20, 2014 02:51
A script to bulk import netflow records into a Neo4j graph database. Designed for efficiency, can import roughly 1 million flows every 2 hours.
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
AUTHOR: Gabriel Bassett
DATE: 11-19-2014
DEPENDENCIES: py2neo
Copyright 2014 Gabriel Bassett
anonymous
anonymous / nn.clj
Created March 24, 2013 16:55
A neural network in Titan and Clojure implementing the xor function
(ns martha.core
(:require [clojurewerkz.titanium.graph :as g]
[clojurewerkz.titanium.vertices :as v]
[clojurewerkz.titanium.edges :as e]
[clojurewerkz.titanium.types :as t]
[ogre.core :as q]))
(def conf {:storage {:backend "embeddedcassandra"
:hostname "127.0.0.1"
:keyspace "martha"
@fogus
fogus / commatize.clj
Created February 7, 2012 18:33 — forked from unclebob/commatize
A function to format a number with commas
(defn commatize [n]
(-> (->> n str seq reverse (partition-all 3) (interpose \,))
flatten
reverse
(#(apply str %))))
(commatize 1000) ;=> "100"
(commatize 100) ;=> "1,000"
(commatize 1000000) ;=> "1,000,000"
@david-mcneil
david-mcneil / custom-clojure-map.clj
Created January 26, 2012 20:43
Creating a custom Clojure map type
(ns people
(:use [clojure.string :only (join)]
[clojure.pprint :only (pprint simple-dispatch)]))
;; we can make maps using the special literal form:
{:a 100
:b 200}
(class {:a 100 :b 200})
@tce
tce / clojureDirectoryList
Created January 18, 2012 21:52
clojure directory listings
(comment "wildcardfilter from http://corfield.org/blog/post.cfm/real-world-clojure-powermta-log-files")
(defn- wildcard-filter
"Given a regex, return a FilenameFilter that matches."
[re]
(reify java.io.FilenameFilter
(accept [_ dir name] (not (nil? (re-find re name))))))
(defn- nonhidden-filter
"return a FilenameFilter that ignores files that begin with dot or end with ~."
(import '(org.joda.time LocalDate))
(defn today [] (LocalDate.))
;; basic functions to increment or decrement a date
(defn inc-date [#^LocalDate ds] (.plusDays ds 1))
(defn dec-date [#^LocalDate ds] (.minusDays ds 1))
;; generate infinite streams of LocalDate objects starting with start-ds
(defn inc-date-stream [#^LocalDate start-ds] (iterate inc-date start-ds))
@claj
claj / dsstuff.clj
Created December 3, 2011 23:57
duck-stream stuff
(ns dsstuff
"things i used to do in duckstreams in clojure 1.2.0")
;;read-lines from files
(defn read-lines-from-file [filename]
(with-open [rdr (clojure.java.io/reader filename)]
(line-seq rdr)))
;;thank you Abhinav Sarkar (http://stackoverflow.com/questions/4118123/read-a-very-large-text-file-into-a-list-in-clojure)
@oneness
oneness / gcount.clj
Created August 19, 2011 06:45
gcount
(ns gcount.core
"generates charts out of the result from google search term(s)."
(:use (incanter core charts))
(:require [clj-http.client :as http-client]))
(def *search-provider* "http://www.google.com/search?hl=en&q=")
(def *search-pattern* #"About.*?([\d,]+).*?")
(defn search-for-term [term]
(let [encoded-term (.replaceAll (apply str term) " " "+")
@JunKikuchi
JunKikuchi / 4clojure: Implement range.clj
Created May 15, 2011 07:08
4clojure: Implement range
#(take (- %2 %1) (iterate inc %1))
@JunKikuchi
JunKikuchi / 4clojure: Duplicate a Sequence.clj
Created May 15, 2011 06:38
4clojure: Duplicate a Sequence
reduce #(conj %1 %2 %2) []