This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = []; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface S3Facade { | |
List<S3File> listObjects(String bucketName); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class S3FilesResource { | |
AmazonS3Client amazonS3Client; | |
// ... | |
@Path("/files") | |
public String listS3Files() { | |
StringBuilder html = new StringBuilder("<html><body>"); | |
List<S3ObjectSummary> files = this.amazonS3Client.listObjects("myBucket").getObjectSummaries(); |
OlderNewer