Skip to content

Instantly share code, notes, and snippets.

View objarni's full-sized avatar

Olof Bjarnason objarni

View GitHub Profile
@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 / 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 / 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 / Story data structure
Created February 13, 2013 10:05
Sagoträd!
data Story = Snippet String Story Story
| End
@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):