Skip to content

Instantly share code, notes, and snippets.

View holyjak's full-sized avatar
💓
Loving Clojure

Jakub Holý holyjak

💓
Loving Clojure
View GitHub Profile
(require '[cheshire.core :refer [parse-string]])
(defn db-array [col] (reify java.sql.Array (getArray [_] (object-array col))))
(defn- json->data [data fields]
(map (fn [data]
(reduce (fn [data field]
(assoc data field (parse-string (get data field) true)))
data fields)) data))
(require '[cheshire.core :refer [parse-string]])
(require '[clojure.set :refer [subset? difference ]])
(defn db-array [col] (reify java.sql.Array (getArray [_] (object-array col))))
(defn- json->data [data fields]
{:pre [(sequential? data) (sequential? fields)]}
(map (fn [data]
(reduce (fn to-json [data field]
{:pre [(map? data) (string? (get data field)) (keyword? field)]}
(require '[cheshire.core :refer [parse-string]])
(defn- json->data [key m]
(update-in m [key] #(parse-string % true)))
(defn- select-campaign [car+campaigns]
(first car+campaigns))
(defn- jdbc-array-to-set
[key m]
var Q = require('q');
var mongoFacade = require('mongoFacade');
/** For each user in our DB, fetch her stats from Fitbit */
var getUsersWithFitbitStats = function(){
var deferred = Q.defer();
//get stats for all users:
var userStats = [];
var Q = require('q');
var mongoFacade = require('mongoFacade');
/** For each user in our DB, fetch her stats from Fitbit */
var getUsersWithFitbitStats = function(){
var deferredResults = Q.defer();
mongoFacade.find({}, function(err, users){ // Async fetch from DB
// Turn each user into a promise of user stats
var userStatsPromisses = users.map(function(user){
@holyjak
holyjak / iterm-notify-test-failure.sh
Last active August 29, 2015 14:20
iTerm coprocess reporting result of (Mocha) tests run via `nodemon`
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Inspired by https://gist.github.com/ddbeck/1421861
# About: This coprocess produces an OSX notification with results of Mocha tests run via nodemon
# # Installation:
# 1. Make this script executable
# 2. Register it: iTerm - Profiles - Open Profiles... - [Edit Profiles...] - <select your profile> -
# - Advanced - Triggers - [Edit] - add a new trigger:
# Regular Expression: [nodemon] starting `npm .*(run )?test.*`
# Action: Run Coprocess
@holyjak
holyjak / 10gor.config.yaml
Last active August 29, 2015 14:26
Configure the HTTP traffic replicator [gor](https://github.com/buger/gor) to run on an AWS Elastic Beanstalk instance as a daemon. Store this file as `./ebextensions/10gor.config`
# File: .ebextensions/10gor.config
# Config Gor to copy a sample of Prod http traffice to staging
files:
# Utility for daemonizing binaries such as gor; see http://libslack.org/daemon
/opt/daemon.rpm:
source: "https://s3-eu-west-1.amazonaws.com/elasticbeanstalk-eu-west-1-<our id>/our_fileserver/daemon-0.6.4-1.x86_64.rpm"
authentication: S3Access # See AWS::CloudFormation::Authentication below
owner: root
group: root
@holyjak
holyjak / S3FilesResourceTest.java
Created September 9, 2012 12:18
S3FilesResourceTest - original
public class S3FilesResourceTest {
@Test
public void listFilesButNotDirectoriesAsHtml() throws Exception {
S3FilesResource resource = new S3FilesResource(/* pass AWS credentials ... */);
String html = resource.listS3Files();
assertThat(html)
.contains("<a href='/content?fileName=/dir/file1.txt'>/dir/file1.txt</a>")
.contains("<a href='/content?fileName=/dir/another.txt'>/dir/another.txt</a>")
.doesNotContain("/dir/</a>"); // directories should be excluded
@holyjak
holyjak / S3Facade.java
Created September 9, 2012 12:22
S3FilesResource - refactored
public interface S3Facade {
List<S3File> listObjects(String bucketName);
}
@holyjak
holyjak / S3FilesResource.java
Created September 9, 2012 11:28
REST service mixing data and representation
public class S3FilesResource {
AmazonS3Client amazonS3Client;
// ...
@Path("/files")
public String listS3Files() {
StringBuilder html = new StringBuilder("<html><body>");
List<S3ObjectSummary> files = this.amazonS3Client.listObjects("myBucket").getObjectSummaries();