Skip to content

Instantly share code, notes, and snippets.

jhartikainen /
Created October 6, 2011 20:43
Very quick Battlelog soldier statistics scraper
# This script scrapes your soldier statistics from Battlelog
# NOTE: This is just a very quick demonstration, it doesn't really do much as-is, besides
# authenticate to Battlelog and get you a dict of your soldier's statistics.
# There is no error handling, no anything. It will only work if everything goes well.
# Input your Origin username and password into the params dict below and it should work.
# In the very bottom, the stats dict will contain the data from the Battlelog JSON response.
jhartikainen / commit-msg
Created February 6, 2015 17:46
ESLint git commit hook
View commit-msg
files=$(git diff --cached --name-only | grep '\.js$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
echo $files | xargs eslint
jhartikainen / DynLoad.hs
Created August 20, 2011 11:31
Module for loading modules dynamically in Haskell
View DynLoad.hs
{-# LANGUAGE ScopedTypeVariables #-}
module DynLoad (
) where
import Control.Exception (throw)
import GHC hiding (loadModule)
import GHC.Paths (libdir)
import HscTypes (SourceError, srcErrorMessages)
jhartikainen / screen.clj
Created May 31, 2012 14:26
Take screenshot with Clojure
View screen.clj
'(java.awt Rectangle Dimension Robot Toolkit)
'(java.awt.image BufferedImage)
'( File IOException)
'(javax.imageio ImageIO))
(defn take-screenshot []
(let [screen (.getScreenSize (Toolkit/getDefaultToolkit))
rt (new Robot)
img (.createScreenCapture rt (new Rectangle (int (.getWidth screen)) (int (.getHeight screen))))]
View gist:889f3843ba8299677f21de16afcbb882
//guess where this fails.
this.x = function() {
(foo || bar).call();
jhartikainen / lol.js
Last active December 13, 2016 01:36
JavaScript doesn't have classes lololo
View lol.js
class X extends Y {
public X() {
public void method() {
public static staticMethod() {
jhartikainen / foo.js
Last active December 4, 2016 14:04
Using angular isolated scopes as event emitters
View foo.js
someModule.service('something', function($rootScope) {
var emitter = $rootScope.$new(true);
var data = whateverStuffHere;
return {
onDataUpdated: function(callback) {
//by returning the result from $on, we get
//the ability to remove event listeners easily
return emitter.$on('update', callback);
jhartikainen / test.js
Last active November 25, 2016 08:43
Avoiding multiple asserts
View test.js
//easy way to check if object has the expected "shape":
it('tests something', function() {
var expectedObject = {
some: 'prop',
values: 'here'
var result = doStuff();
assert.deepEqual(result, expectedObject);
jhartikainen / timeouts.js
Created September 5, 2016 23:50
Chained timeouts
View timeouts.js
var moves = []..
function makeMove() {
var m = moves.shift();
if(!m) {
return everythingDone();
setTimeout(function() {
jhartikainen / chain.js
Created September 5, 2016 23:11
Chained promises
View chain.js
//let's say all the moves are in this array
var moves = [...];
moves.reduce(function(p, move) {
return p.then(activateWithDelay(move.button))
}, Promise.resolve());