Skip to content

Instantly share code, notes, and snippets.

View Gautier's full-sized avatar

Gautier Hayoun Gautier

View GitHub Profile
@Gautier
Gautier / CountDownTimer.java
Created December 12, 2010 00:58
Drop-in alternative for the Android CountDownTimer class, but which you can cancel from within onTick.
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@Gautier
Gautier / pendulum.js
Created March 16, 2010 00:13
Javascript pendulum CSS3
/**
* Oh yeah
*/
function rotate(id) {
var element = document.getElementById(id);
function applyRotate(angle) {
var strAngle = "rotate(" + angle + "rad)";
element.style.WebkitTransform = strAngle;
element.style.MozTransform = strAngle;
}
<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