Skip to content

Instantly share code, notes, and snippets.

View scotthaleen's full-sized avatar
λ

スコット scotthaleen

λ
View GitHub Profile
(def lookup-int-val
(merge
{\* 36 \@ 37 \# 38}
(zipmap (map char(range 48 58)) (range))
(zipmap
(map char (range 65 91))
(drop 10 (range)))))
(defn inc-sum [sum v i]
(let [val (if (even? i) (* 2 v) v)]
@scotthaleen
scotthaleen / reorganize-list.clj
Last active August 29, 2015 13:56
Given a list and a vector of indexes -- return a reorganized list from the indexes supplied, e.g. [A B C] [2 3 1] => [B C A]
(defn reorganize-list
([lst idxs] (reorganize-list lst idxs nil))
([lst idxs out-of-range]
(let [n (fn [i] (fn [l] (nth l i out-of-range)))
f (apply juxt (map n idxs))]
(f lst))))
;;=> (reorganize-list (range 10 20) [1 -1 5] 99)
;;[11 99 15]
@scotthaleen
scotthaleen / 0_reuse_code.js
Created June 2, 2014 23:26
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@scotthaleen
scotthaleen / emacs-list.sh
Created August 29, 2014 00:53
debian emacs install
wget -q http://londo.ganneff.de/apt.key -O- | apt-key add -
echo "deb http://londo.ganneff.de wheezy main" > /etc/apt/sources.list.d/emacs.list
aptitude update
aptitude install emacs-snapshot
@scotthaleen
scotthaleen / spark_es_search_list.py
Last active August 29, 2015 14:24
Spark Elastic Search List
#!/usr/bin/env python
from pyspark import SparkContext, SparkConf
import urllib2
import json
conf = SparkConf().setAppName("ES Search List")
sc = SparkContext(conf=conf)
url='localhost:9200'
@scotthaleen
scotthaleen / elastic_bulk_ingest.py
Created October 22, 2015 19:29
Bulk Index json to elastic search
from pyspark import SparkContext, SparkConf
import json
import argparse
def fn_to_doc(line):
try:
doc = {}
data = json.loads(line)
doc['data'] = data
@scotthaleen
scotthaleen / lein_jars_local.txt
Created October 26, 2015 18:37
leiningen download project dependencies locally
# download transitive dependencies to local directory
lein pom
mvn dependency:copy-dependencies
ls -la target/dependency/
@scotthaleen
scotthaleen / gmail_downloader.py
Created November 4, 2015 15:41
Download Gmail
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
import imaplib
import email
from email.utils import getaddresses
import datetime
import getpass
import argparse
(defvar helm-fzf-source
(helm-build-async-source "fzf"
:candidates-process 'helm-fzf--do-candidate-process
:nohighlight t
:requires-pattern 2
:candidate-number-limit 9999))
(defun helm-fzf--do-candidate-process ()
(let* ((cmd-args `("fzf" "-x" "-f" ,helm-pattern))
(proc (apply #'start-file-process "helm-fzf" nil cmd-args)))