Skip to content

Instantly share code, notes, and snippets.

View Gautier's full-sized avatar

Gautier Hayoun Gautier

View GitHub Profile
<link rel="import" href="../core-menu/core-submenu.html">
<link rel="import" href="../core-item/core-item.html">
<link rel="import" href="../core-pages/core-pages.html">
<link rel="import" href="../paper-radio-group/paper-radio-group.html">
<link rel="import" href="../paper-radio-button/paper-radio-button.html">
<polymer-element name="my-element">
<template>
<style>
@Gautier
Gautier / jsToggler.js
Created March 2, 2013 20:29
An old jetpack experiment
jetpack.statusBar.append({
html: "<input type='button' value='Disable Javascript' id='jsEnabler' />",
onReady: function(widget){
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefService).getBranch("");
var jsEnabled = prefs.getBoolPref("javascript.enabled");
var button = $(widget).find("#jsEnabler");
if(!jsEnabled) button.val("Enable Javascript");
$(widget).click(function(){
if(jsEnabled) {
jetpack.notifications.show( "Disabling Javascript" );
@Gautier
Gautier / Makefile
Created September 20, 2012 09:46
Makefile for arduino avr programs
MCU='atmega328p'
F_CPU=16000000
PORT='/dev/ttyACM0'
UPLOAD_RATE=115200
SOURCES=main.c
all: compile
compile: build/main.hex
@Gautier
Gautier / mini_bench.py
Created August 7, 2012 14:49
Benchmark arbitrary command n times
#!/usr/bin/env python
import subprocess
import sys
import time
def avg(nums):
return sum(nums) / len(nums)
def main():
if len(sys.argv) < 3:
""" from Paul Moore at
http://code.activestate.com/recipes/535141-console-progress-dots-using-threads-and-a-context-/ copied here as a bookmark"""
import sys
import threading
class Ticker(threading.Thread):
def __init__(self, msg):
threading.Thread.__init__(self)
self.msg = msg
self.event = threading.Event()
@Gautier
Gautier / tests_timer.py
Created May 17, 2012 09:20
Prints the 5 slowest tests and their running time in ms
"""
>>> import unittest
>>> class MyTestCase(TestsTimer, unittest.TestCase):
... def test_add(self):
... self.assertEqual(1 + 2, 3)
>>> suite = unittest.TestLoader().loadTestsFromTestCase(MyTestCase)
>>> unittest.TextTestRunner(verbosity=0).run(suite) # doctest:+ELLIPSIS
[('test_add', ...)]
<unittest.runner.TextTestResult run=1 errors=0 failures=0>
"""
@Gautier
Gautier / datepickermixin.py
Created April 17, 2012 16:15
DatePickerMixIn
class DatePickerMixIn(object):
def prepare_datefields(self):
for field in self.fields:
if isinstance(self.fields[field], forms.fields.DateField):
self.fields[field].widget.attrs.update({'class':'datepicker'})
@Gautier
Gautier / example_websocket.py
Created April 13, 2012 15:07
example websocket
from django.core.management import setup_environ
from asyncdb import settings
setup_environ(settings)
from core.models import Help
from eventlet import wsgi
import eventlet
import websocket
@Gautier
Gautier / dalton_base_test.py
Created February 7, 2012 12:56
DaltonTestCase
import os
import dalton
from django.test import TestCase
from django.conf import settings
class DaltonTestCase(TestCase):
ROOT_DIR = os.path.join(os.path.abspath(os.path.dirname(__file__)),
"replay")
@Gautier
Gautier / twit.py
Created July 7, 2011 19:40
Group1 code dojo secret sauce
import urllib2
import json
import urllib
API_URL = "http://search.twitter.com/search.json"
def find_a_tweet_without_twitter_stuff(tweets):
for tweet in tweets:
if not ("#" in tweet or "@" in tweet or "http://" in tweet):
yield tweet