Skip to content

Instantly share code, notes, and snippets.

View objarni's full-sized avatar

Olof Bjarnason objarni

View GitHub Profile
@objarni
objarni / alarm.py
Created September 14, 2012 06:25 — forked from Neppord/alarm.py
fuse variation
import random
class Sensor(object):
OFFSET = 16
def pop_next_pressure_psi_value(self):
pressure_telemetry_value = self.sample_pressure()
return Sensor.OFFSET + pressure_telemetry_value
def __iter__(self):
@objarni
objarni / Story data structure
Created February 13, 2013 10:05
Sagoträd!
data Story = Snippet String Story Story
| End
@objarni
objarni / SaneWinPython3Environment
Last active December 15, 2015 07:09
Lazy me likes to install pip on a windows machine with git-bash on it. Here's the rows!
# COMMAND PROMPT ENVIRONMENT
python -c "import urllib.request;open('distribute_setup.py', 'wb').write(urllib.request.urlopen('http://python-distribute.org/distribute_setup.py').read())"
python distribute_setup.py
python -c "import urllib.request;open('get-pip.py', 'wb').write(urllib.request.urlopen('https://raw.github.com/pypa/pip/master/contrib/get-pip.py').read())"
python get-pip.py
# GIT-MSYS ENVIRONMENT
curl -O http://python-distribute.org/distribute_setup.py
python distribute_setup.py
@objarni
objarni / gist:5680411
Created May 30, 2013 19:21
Selenium-Python lathund!
# hitta element baserat på id
elem = driver.find_element_by_id('some-id')
# hitta element baserat på class
elem = driver.find_element_by_xpath("//*[contains(@class, 'some-class')]")
# hitta element baserat på del-av-id
elem = driver.find_element_by_xpath("//*[contains(@id,'some-id-substring')]")
@objarni
objarni / dirt
Last active December 18, 2015 13:39
When learning a new module in Python, I often go into the interpreter and use dir/help over and over. But dir() gives so many results, and unstructured too. So I've created a little helper function.
def dirt(module, substring=''): print('\n'.join((d for d in dir(module) if substring in d)))
Usage:
$ python
Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:55:48) [MSC v.1600 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def dirt(module, substring=''): print('\n'.join((d for d in dir(module) if substring in d)))
...
>>> import os.path
@objarni
objarni / many_ffs.py
Created November 1, 2013 23:38
Hack to run multiple selenium browser at the same time
import multiprocessing
import time
from browserdriver import BrowserDriver
def readfile(fname):
with open(fname) as f:
content = f.read()
#print("Read value " + content + " from file " + fname)
return content
@objarni
objarni / install_spotify
Created December 31, 2013 16:20
A bash script to install spotify on ubuntu based linux.
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4E9CFF4E
sudo sh -c 'echo "deb http://repository.spotify.com stable non-free" >> /etc/apt/sources.list'
sudo apt-get update && sudo apt-get install spotify-client-qt
@objarni
objarni / setup_objarni_lubuntu_env.sh
Created January 4, 2014 19:42
Setup my own comfy' Lubuntu development environment.
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install adobe-flashplugin
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4E9CFF4E
sudo sh -c 'echo "deb http://repository.spotify.com stable non-free" >> /etc/apt/sources.list'
sudo apt-get update && sudo apt-get install spotify-client-qt -y --force-yes
@objarni
objarni / CheapDigiSign.html
Last active December 3, 2015 18:22
Poor mans digital sign
<html>
<head>
<title>Poor mans digital sign</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script>
var urls = [
'http://www.bloggar.se',
'http://www.knuff.se',
@objarni
objarni / homepage.html
Last active August 29, 2015 14:00
Poor mans browser start page
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<title>Start page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<style type="text/css">