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
@holyjak
holyjak / S3FilesResourceTest.java
Created September 9, 2012 12:53
S3FilesResourceTest - refactored
public class S3FilesResourceTest {
private static class FakeS3Facade implements S3Facade {
List<S3File> fileList;
public List<S3File> listObjects(String bucketName) {
return fileList;
}
}
@holyjak
holyjak / pre-commit
Created March 27, 2015 20:03
Git pre-commit hook that fails for changes introducing Jest/Jasmine's exclusive tests using "it.only"
#!/bin/sh
# A git pre-commit hook that verifies that the change does not introduce
# the use of a Jest/Jasmine exclusive test via 'it.only(..)', which would
# prevent most other tests from being run without any clear indication thereof
# Redirect output to stderr.
exec 1>&2
ADDED_IT_ONLY=$(git diff -U0 --cached -S"(\W|^)it\.only\s+?\(" --pickaxe-regex | egrep "(^\+.*it.only)|\+{3}")
@holyjak
holyjak / low-on-stock.cljs.md
Last active October 21, 2015 21:09
Refactoring & Type Errors in Clojure

Refactoring & Type Errors in Clojure

While refactoring a relatively simple Clojure code to use a map instead of a vector, I have wasted perhaps a few hours due to essentially type errors. I want to share the experience and my thoughts about possible solutions since I encounter this problem quite often. I should mention that it is quite likely that it is more a problem (an opportunity? :-)) with me rather than the language, namely with the way I write and (not) test it.

The core of the problem is that I write chains of transformations based on my

@holyjak
holyjak / 11gor.config.yaml
Created July 29, 2015 08:10
Fixing a mysterious .ebextensions command time out (AWS Elastic Beanstalk)
files:
/opt/gor:
source: "https://s3-eu-west-1.amazonaws.com/elasticbeanstalk-eu-west-1-<our-id>/our_fileserver/gor"
authentication: S3Access
mode: "000755"
owner: root
group: root
# Script to start Gor in the background
@holyjak
holyjak / filter.js
Last active November 20, 2015 10:33
Simple or Complex? Familiar Imperative Code Or Makes-Me-Think Declarative One?
// Using http://lodash.com/ as `_`
// 1. IMPERATIVE
_(bundles).filter(function includeOnlyHandsets(bundle) {
if (!filter.hardwareType) return true;
return (bundle.product.type === filter.hardwareType);
})
// 2. DECLARATIVE
_(bundles).filter(filter.hardwareType ?
@holyjak
holyjak / A_Client.py
Created May 4, 2013 15:45
Method Promiscuity Or The Case For Encapsulation: Do not expose more information and structure to the clients than necessary
...
# The client code
@my.route('/cleanjson/<collection>/')
def getcleanjson(collection):
cleandata = Cleanjson()
cleandata.get_mongojson(str(collection), "?s={'_id': 1}")
cleandata.parse_json(cleandata.rawjson)
return cleandata.cleanjson
@holyjak
holyjak / A_Client2.py
Created May 4, 2013 16:00
Method Promiscuity Or The Case For Encapsulation: Do not expose more information and structure to the clients than necessary - improved version See https://gist.github.com/jakubholynet/5517865
...
# The client code
@my.route('/cleanjson/<collection>/')
def getcleanjson(collection):
return Cleanjson().get_mongojson(str(collection), "?s={'_id': 1}", format=True)
@holyjak
holyjak / LogEntry.java
Last active December 17, 2015 00:00
Simple vs. Easy: Writing A Generic Code To Avoid Duplication - replacing a number of anemic data structures with a generic one - BEFORE See http://wondersofcode.wordpress.com/2013/05/04/simple-vs-easy…id-duplication/
public interface LogEntry {
Date getTimestamp();
/** For dumping into a .tsv file to be imported into Hadoop */
String toTabDelimitedString();
String getSearchTerms();
boolean hasSearchTerms();
String[][] getColumns();
String getKey();
void mergeWith(LogEntry entry);
}
@holyjak
holyjak / LogEntry2.java
Created May 4, 2013 17:40
Simple vs. Easy: Writing A Generic Code To Avoid Duplication - replacing a number of anemic data structures with a generic one - IMPROVED. See http://wondersofcode.wordpress.com/2013/05/04/simple-vs-easy…id-duplication/
public interface LogEntry {
// same as before
}
@holyjak
holyjak / augmentSeriesWithPreviousValues.js
Last active December 17, 2015 00:29
Intention Hidden In Implementation And Misty Edge of Validity - why does this function do what it does and under what assumptions does it operate? See http://wondersofcode.wordpress.com/2013/05/05/intention-hidden-in-implementation-and-misty-edge-of-validity/
// compare two series and add the delta to the data for the current period
augmentSeriesWithPreviousValues:function (seriesData, previousSeriesData) {
var series = seriesData.series;
seriesData.previous = [];
var previousSeries = previousSeriesData.series;
... // checks, computing maxRows, maxColumns, previousCategories
// that maps category name to series index (id)
for (var seriesId = 0; seriesId < series.length; seriesId++) {