Skip to content

Instantly share code, notes, and snippets.

@jhartikainen
jhartikainen / vuetest.js
Last active Feb 13, 2016
Vue.js example component unit test
View vuetest.js
var assert = require('assert');
var Vue = require('vue');
var TestComponent = Vue.extend({
data: function() {
return {
active: false
};
},
@jhartikainen
jhartikainen / spyOn.js
Created Jul 22, 2015
sinon.spy wrapper for IE8
View spyOn.js
/**
* Spy on an object in a way that IE8 likes it
*
* If trying to use sinon.spy(document, 'createElement') or such in IE8,
* it will not work correctly. This function wraps the call in a way
* that it's supported in IE.
*
* May have possible side-effects to more specialized asserts,, but
* at least calledWith, return values, etc. * work correctly.
*
@jhartikainen
jhartikainen / commit-msg
Created Feb 6, 2015
ESLint git commit hook
View commit-msg
#!/bin/bash
files=$(git diff --cached --name-only | grep '\.js$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
fi
echo $files | xargs eslint
@jhartikainen
jhartikainen / bot.js
Last active Oct 20, 2015
Slack JavaScript REPL bot
View bot.js
var Slack = require('slack-client');
var vm = require('vm');
var s = new Slack('api key here', true, true);
s.on('message', function(msg) {
if(msg.type != 'message') {
return;
}
View gist:3567606e462dba5b319d
GET TO THE CHOPPER nextPiece
HERE IS MY INVITATION currentPiece
GET UP forwardAmount
ENOUGH TALK
GET TO THE CHOPPER maxSize
HERE IS MY INVITATION track.size
GET DOWN 1
ENOUGH TALK
View gist:5798641
require 'spec_helper'
feature 'foo', :js => true do
it "hi" do
visit "/login"
# this screenshot exposes the issue in this case
save_screenshot('foo.jpg')
end
end
View gist:5262035
var oldAddEventListener = window.addEventlistener;
var handlers = [];
window.addEventListener = function(event, handler, useCapture) {
handlers.push({ event: event, handler: handler });
oldAddEventListener.call(window, event, handler, useCapture);
};
View gist:4218583
{-# LANGUAGE NoImplicitPrelude #-}
module Test where
import Language.Fay.Prelude
import Language.Fay.FFI
data Server = Server
{ name :: String
, age :: String
, popstate :: String
@jhartikainen
jhartikainen / segfault.hs
Created Sep 26, 2012
Segfault on Ubuntu 12.04 GHC 7.4.1
View segfault.hs
{-# LANGUAGE BangPatterns #-}
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as L
import Data.PEM (PEM(..), pemParseBS)
import Data.Certificate.X509
import Data.Either
main :: IO ()
main = do
certdata <- B.readFile "7d0b38bd.0"
@jhartikainen
jhartikainen / screen.clj
Created May 31, 2012
Take screenshot with Clojure
View screen.clj
(import
'(java.awt Rectangle Dimension Robot Toolkit)
'(java.awt.image BufferedImage)
'(java.io 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))))]