Skip to content

Instantly share code, notes, and snippets.

View Jim-Holmstroem's full-sized avatar
💭
Coding

Jim Holmström Jim-Holmstroem

💭
Coding
View GitHub Profile
@Jim-Holmstroem
Jim-Holmstroem / main.hs
Created February 2, 2017 13:22
Simple Stack Machine Experimentation
{-# LANGUAGE OverloadedStrings #-}
import Prelude hiding (Word)
import Data.Maybe
data Stack a = Stack [a] deriving
(Show)
empty :: Stack a
empty = Stack []
@Jim-Holmstroem
Jim-Holmstroem / install_python_appium_linux.sh
Last active November 18, 2016 09:41
Python Appium on Linux
sudo npm install -g appium-doctor
appium-doctor # find out what is missing, like JAVA_HOME=/usr/lib/jvm/java-7-openjdk
# alternative (via git)
git clone [email protected]:appium/appium.git
cd appium
npm install
cd -
# otherwise
@Jim-Holmstroem
Jim-Holmstroem / firefox_build_prerequisits.sh
Created August 18, 2016 14:31
Build firefox on fedora, what to install
sudo dnf install @development-tools @c-development autoconf213 gtk3-devel GConf2-devel dbus-glib-devel yasm-devel alsa-lib-devel pulseaudio-libs-devel
function syntaxHighlight(json) {
json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
return json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) {
var cls = 'number';
if (/^"/.test(match)) {
if (/:$/.test(match)) {
cls = 'key';
} else {
cls = 'string';
}
@Jim-Holmstroem
Jim-Holmstroem / robosnake.ino
Last active August 8, 2016 13:07
robosnake first draft
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>
// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);
#define SERVOMIN 200 // this is the 'minimum' pulse length count (out of 4096)
#define SERVOMAX 500 // this is the 'maximum' pulse length count (out of 4096)
@Jim-Holmstroem
Jim-Holmstroem / random_context.py
Created July 5, 2016 08:59
Random seed context for python. Use a specific seed just within context, then restore the outer seed when jumping back out
class RandomContext(object):
""" Use to have a specific seed inside of a context and then restore the seed when jumping back out
NOTE random seed is still global
Usage:
import random; random.seed()
print(random.uniform(0, 1))
with RandomContext(random, 1337) as r:
print(r.uniform(0, 1))
@Jim-Holmstroem
Jim-Holmstroem / dockerlatest.sh
Created June 24, 2016 10:16
run latest docker image build (really nice when a build fails and you just want to jump in and see what is happening)
docker run -it $(docker images -q | head -n 1) bash
@Jim-Holmstroem
Jim-Holmstroem / sampling_simulation.py
Last active November 6, 2016 12:37
A simulation of the probability of the turn-out for a voting when you have a sample of the voters (n_samples (number of voters sampled), p_obs (the turnout of the sample))
from __future__ import division, print_function
from itertools import *
from functools import *
from operator import *
from collections import *
from joblib import Parallel, delayed
import numpy as np
@Jim-Holmstroem
Jim-Holmstroem / selenium_firefox_log.py
Last active July 5, 2016 13:26
Get the log from firefox when running it selenium headless
from selenium.webdriver import Firefox
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
import sys
driver = Firefox(firefox_binary=FirefoxBinary(log_file=sys.stdout))
@Jim-Holmstroem
Jim-Holmstroem / gist:7e8614b0472277ea1816bccd877ee3af
Created April 18, 2016 08:29
First try (not working): Functor over Functor as Functor
Prelude> data TwoD f g a = TwoD (f (g a)) deriving Show
Prelude> TwoD [Just 3]
TwoD [Just 3]
Prelude> :t TwoD [Just 3]
TwoD [Just 1] :: Num a => TwoD [] Maybe a
Prelude> :{
Prelude| instance (Functor f, Functor g) => Functor (TwoD f g) where
Prelude| fmap o = fmap (fmap o)
Prelude| :}