Skip to content

Instantly share code, notes, and snippets.

View jamesdavidson's full-sized avatar

James Davidson jamesdavidson

View GitHub Profile
@rcampbell
rcampbell / s3.clj
Created May 11, 2011 10:14
Storing and retrieving Clojure data structures as GZIP compressed JSON in Amazon S3
(ns aws.s3
(:refer-clojure :exclude [get])
(:use [clojure.walk :only (keywordize-keys stringify-keys)]
[clojure.contrib.def :only (defonce-)]
[clojure.contrib.json :only (read-json write-json)])
(:import [java.io PrintWriter InputStreamReader ByteArrayInputStream ByteArrayOutputStream]
[java.util.zip GZIPInputStream GZIPOutputStream]
[com.google.common.base Charsets]
[com.amazonaws.services.s3 AmazonS3Client]
[com.amazonaws.services.s3.model Region CreateBucketRequest ObjectMetadata
;; depends on [org.imgscalr/imgscalr-lib "4.2"]
(ns XXX.image
(:refer-clojure :exclude [read])
(:require [clojure.java.io :as io])
(:import [org.imgscalr Scalr Scalr$Method Scalr$Mode]
[java.awt Image]
[java.awt.image RenderedImage BufferedImageOp]
[javax.imageio ImageIO ImageWriter ImageWriteParam IIOImage]
@dps
dps / gist:4189760
Created December 2, 2012 16:52
Python code to convert seconds since epoch to ISO format (for kml, xml datetime etc)
dt = datetime.datetime.utcfromtimestamp(seconds_since_epoch)
iso_format = dt.isoformat() + 'Z'
@halyph
halyph / App.java
Created May 14, 2013 16:02
Generate DataMatrix, inline it in PDF and read generate DataMatrix
package org.halyph.barcode;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@stathissideris
stathissideris / channel-as-seq.clj
Last active October 20, 2020 19:14
clojure async channels as lazy (and blocking!) sequences
(defn seq!!
"Returns a (blocking!) lazy sequence read from a channel."
[c]
(lazy-seq
(when-let [v (<!! c)]
(cons v (seq!! c)))))
(comment
(def stream (chan))
(go (dotimes [x 16]
@SegFaultAX
SegFaultAX / gist:10941721
Last active May 19, 2023 09:20
clojure.walk in Python
from functools import partial
def identity(e):
return e
def walk(inner, outer, coll):
if isinstance(coll, list):
return outer([inner(e) for e in coll])
elif isinstance(coll, dict):
return outer(dict([inner(e) for e in coll.iteritems()]))
@NightOwl888
NightOwl888 / BitSet.cs
Last active November 13, 2024 07:21
C# port of the java.util.BitSet class
/* BitSet.cs -- A vector of bits.
Copyright (C) 1998, 1999, 2000, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
@mdamien
mdamien / ita.md
Last active December 14, 2017 13:07

The founder of Mixergy.com, home of the ambitious upstart. The place where over a thousand of entrepreneurs have come to tell the stories of how they built their businesses, had challenges along the way, overcame them, or not, and mostly told you what they learned from it. And thousands and thousands and thousands of other entrepreneurs have listened and learned, and used what they’ve learned from these interviews.

Today’s guest is David Baggett. He co-founded ITA software, a company that Google bought for a reported $700 million. ITA makes software that’s the search engine behind sites like Kayak. It actually figures out prices, time and other data like flights.

Today, after selling, he launched, and is running, Inky, a mobile app that makes clearing your inbox easier. It will categorize your email for you., it will help you unsubscribe from junk. And it will let you quickly respond to what’s important.

I invited him here to talk about his past companies. And personally he’s a guy wh

@s-fujimoto
s-fujimoto / s3-to-es-lamba.py
Created November 14, 2015 15:57
Import Elasticsearch from ELB access log for AWS Lambda Function
##################################################
### Elasticsearch host name
ES_HOST = "search-******************.ap-northeast-1.es.amazonaws.com"
### Elasticsearch prefix for index name
INDEX_PREFIX = "awslogs"
#################################################
### ELB access log format keys
ELB_KEYS = ["timestamp", "elb", "client_ip", "client_port", "backend_ip", "backend_port", "request_processing_time", "backend_processing_time", "response_processing_time", "elb_status_code", "backend_status_code", "received_bytes", "sent_bytes", "request_method", "request_url", "request_version", "user_agent"]
@vkz
vkz / bleval.clj
Created December 15, 2015 12:39
Clojure's `eval` and namespaces
;; Clojure's eval is dynamic with respect to current namespace.
;; If you ever find yourself in need of eval but want to avoid **wat**
;; moments here's hopefully an illuminating sequence:
user> (in-ns 'bla)
#namespace[bla]
bla> (refer-clojure)
nil
bla> (def x "bla")
#'bla/x
bla> (defn bleval [s]