Skip to content

Instantly share code, notes, and snippets.

View franchb's full-sized avatar
🎯
Focusing

Eliah Rusin franchb

🎯
Focusing
View GitHub Profile
@jacobian
jacobian / elem2dict.py
Created January 25, 2011 20:22
Convert an lxml.etree node tree into a dict.
def elem2dict(node):
"""
Convert an lxml.etree node tree into a dict.
"""
d = {}
for e in node.iterchildren():
key = e.tag.split('}')[1] if '}' in e.tag else e.tag
value = e.text if e.text else elem2dict(e)
d[key] = value
return d
@jaimefjorge
jaimefjorge / style.scala
Created July 20, 2011 07:46
Scala Coding Method Chaining style
/**
* This is from community accepted conventions and feel free to judge upon them.
*
* Upon Method Invocation chaining, one can prefer the 'fooIndent' method over 'fooNotIndent'
* (as well as barIndent over barNotIndent),
* Not only it improves readibility upon reading (by gradually grasping the functionality) but also it does not consume
* the whole screen (thus not making you scroll).
*
* The use of '.' upon invocation is debatable.
* Some argue that the leading '.' should be removed [2]
@domenkozar
domenkozar / autovpn.py
Created January 1, 2012 16:00 — forked from anonymous/autovpn.py
AutoVPN for NetworkManager
#!/usr/bin/env python
"""
Copyright 2011 Domen Kozar. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
@casschin
casschin / gist:1990245
Created March 7, 2012 01:16
Python webdriver api quick sheet
### Locating UI elements ###
# By ID
<div id="coolestWidgetEvah">...</div>
element = driver.find_element_by_id("coolestWidgetEvah")
or
from selenium.webdriver.common.by import By
element = driver.find_element(by=By.ID, value="coolestWidgetEvah")
# By class name:
@nunoveloso
nunoveloso / nuno_php_array_ops.php
Created March 7, 2012 12:34
PHP array operations up to 10x faster than the original
/**
* Home mande method to do array_diff ~10x faster that PHP built-in.
*
* @param The array to compare from
* @param An array to compare against
*
* @return an array containing all the entries from array1 that are not present in array2.
*/
function nuno_array_diff($array1, $array2) {
$diff = array();
@jboner
jboner / latency.txt
Last active June 2, 2024 14:49
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@nhoffman
nhoffman / pyscript.py
Last active May 8, 2024 14:26
Python script template
#!/usr/bin/env python3
"""A simple python script template.
"""
import os
import sys
import argparse
@ibeex
ibeex / foo.log
Created August 4, 2012 13:46
Flask logging example
A warning occurred (42 apples)
An error occurred
@huangzhichong
huangzhichong / selenium-webdriver-cheatsheet.md
Created August 7, 2012 12:38
Selenium Webdriver CheatSheet

API workthough

  1. Open a browser

    # start an instance of firefox with selenium-webdriver
    driver = Selenium::WebDriver.for :firefox
    # :chrome -> chrome
    # :ie     -> iexplore
    
  • Go to a specified URL
@jkodumal
jkodumal / RecIso.scala
Created September 22, 2012 16:57
Type-safe transformation from nested case classes to HLists using shapeless
// Based on shapeless 1.2.2
import shapeless._, HList._
trait RecIso[T, R] {
def iso(t: T) : R
}
trait RecId[T] extends RecIso[T, T] {
def iso(t: T) : T = t
}