Skip to content

Instantly share code, notes, and snippets.

@shuhaowu
shuhaowu / release.sh
Created March 27, 2016 04:52
For releasing packages to PPA.
#!/bin/bash
set -e
PROJECT=$1
PPA_ID=$2
if [ -z $PROJECT ] || [ -z $PPA_ID ]; then
>&2 echo "usage: ./release.sh directory ppa_id"
exit 1
from fabric.api import run
def check_apt():
apt_sha = "cfd9d742f7c99d55214257fdad42ead547547c5a05af9d4569a256205af28fa7"
result = run("sha256sum /var/cache/apt/archives/apt_0.9.7.9+deb7u3_amd64.deb")
if apt_sha in result:
print "Everything is okay"
else:
print "Potential attack?"
@shuhaowu
shuhaowu / wipe_riak.py
Created January 29, 2014 20:32
Purges all keys from riak via python.
import riak
import multiprocessing
keys = []
c = riak.RiakClient()
for b in c.get_buckets():
k = [(b.name, key) for key in b.get_keys()]
keys.extend(k)
@shuhaowu
shuhaowu / gist:6177897
Created August 7, 2013 19:51
Student t's distribution approximation
from __future__ import division
from math import sqrt, log, pi, cos, sin, expm1
_a1 = -3.969683028665376e+01
_a2 = 2.209460984245205e+02
_a3 = -2.759285104469687e+02
_a4 = 1.383577518672690e+02
_a5 = -3.066479806614716e+01
_a6 = 2.506628277459239e+00
_b1 = -5.447609879822406e+01
@shuhaowu
shuhaowu / mergerange.py
Last active December 15, 2015 12:09
Consider this public domain. This takes a sorted number range and merges the overlapping ones. If you just have a bunch of number ranges, you could always sort and then pass it in to this.
def merge_range_sorted(r):
"""Merges and sorts a range of numbers. Used for block merging.
Worse-case runtime:
O(n)
Args:
r: A **sorted**, from low to high, list of ranges in a tuple format.
Returns:
@shuhaowu
shuhaowu / statusmsg.coffee
Last active December 10, 2015 11:49
Status message like the gmail sending messages. An updated version of http://code.google.com/p/humanmsg/, perhaps you can see from some functions This has been DEPRECATED. Use https://github.com/shuhaowu/awesome-statusmsg instead
# This has been deprecated. Use https://github.com/shuhaowu/awesome-statusmsg instead
window["statusmsg"] = statusmsg = {}
# statusmsg = namespace "statusmsg"
# I use my own namespace function from coffeecrispt so not sure how well that first line works.
# To use, do statusmsg.setup() at document load
# Then you can do statusmsg.display("Your text") and close via statusmsg.close()
set_human_msg_css = (msgbox) ->
@shuhaowu
shuhaowu / relative_time.js
Last active October 12, 2015 07:48
Relative time helper like twitter in JavaScript
var relative_time = function(timestamp, relative_to) {
if (timestamp === null || timestamp === undefined)
return "";
var delta, relative_is_future, t;
if (!relative_to)
relative_to = parseInt(new Date().getTime() / 1000);
if ($.type(timestamp) !== "number")
@shuhaowu
shuhaowu / markdownproperty.py
Created October 18, 2012 19:38
MarkdownProperty for Riakkit
from riakkit import DictProperty, BaseProperty
import markdown
from lxml.html.clean import Cleaner
_cleaner = Cleaner(add_nofollow=True, style=True)
_markdown = markdown.Markdown(safe_mode="escape")
class MarkdownProperty(BaseProperty):
class MD(DictProperty.DotDict):
def get(self, markdown):
@shuhaowu
shuhaowu / coffeescript.json
Created August 17, 2012 23:09
Coffeescript syntax file for ninja-ide 2
{
"comment": [
"#"
],
"extension": [
"coffee"
],
"definition": [
"class"
],
@shuhaowu
shuhaowu / stop_charge
Created May 15, 2012 23:13
Thinkpad ACPI Set Stop Charge Script for Ubuntu
#!/bin/bash
echo -ne "Changing stop charge threshold from "
cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh | tr -d "\n"
sudo sh -c "echo $1 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh"
echo -ne " to "
cat /sys/devices/platform/smapi/BAT0/stop_charge_thresh