Skip to content

Instantly share code, notes, and snippets.

// Sublime Text
{
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"font_face": "DejaVu Sans Mono",
"font_size": 10,
"ignored_packages":
[
"Vintage"
],
"translate_tabs_to_spaces": true,
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.background {
fill: #e7e7e7;
}
.axis path,
.axis line {
@eliangcs
eliangcs / shortcuts.sh
Last active January 18, 2016 06:29
Shell shortcuts
# Clear local merged branches
function clearbranches(){
cur_branch=`git rev-parse --abbrev-ref HEAD`
if [[ "$cur_branch" == "master" ]]; then
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
else
echo "Not on master branch!"
fi
}
@eliangcs
eliangcs / index.html
Last active January 18, 2016 06:44
Integrating sine with Monte Carlo / Metropolis algorithm
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.svg {
border: 1px solid #000;
}
.result {
color: #05c;
@eliangcs
eliangcs / guess_encoding.py
Created January 22, 2016 06:37
Guess encoding by looking at the content
def guess_encoding(s):
"""Guess the character encoding from a byte string."""
# Check BOM
# 0xFF, 0xFE -> UTF-16 LE
# 0xFE, 0xFF -> UTF-16 BE
# 0xEF, 0xBB, 0xBF -> UTF-8
bom = s[0:2]
if bom == '\xff\xfe':
return 'utf-16'
elif bom == '\xfe\xff':
@eliangcs
eliangcs / time_celery_task.py
Last active December 16, 2016 17:45
Log execution time for every Celery task, working on Celery 3.1.x.
import logging
import time
from celery import shared_task as orig_shared_task
def timeit(func):
"""A decorator used to log the function execution time."""
logger = logging.getLogger('tasks')
@eliangcs
eliangcs / search_github_issues_and_prs.py
Last active November 2, 2017 10:02
Script Filter for Alfred listing all the issues and PRs assigned to or created by you
#!/Users/YOUR_USERNAME/.pyenv/versions/3.6.2/envs/alfred/bin/python
import functools
import json
import os
from datetime import datetime
from threading import Thread
import requests
@eliangcs
eliangcs / postgres9.3-install.sh
Last active May 28, 2018 11:33
Install PostgreSQL 9.3 on Ubuntu 12.04 LTS
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo apt-get update
sudo apt-get upgrade
# sudo apt-get install postgresql-9.3
# sudo apt-get install postgresql-client-9.3
@eliangcs
eliangcs / httplogger.sh
Created July 27, 2018 03:48
A minimal netcat web server that prints everything it gets
httplogger() {
while true; do
echo -e "HTTP/1.1 200 OK\r\n\r\nok" | nc -vl 8989
test $? -gt 128 && break
echo
echo '----------------------------------------'
done
echo
}
@eliangcs
eliangcs / tornado_subprocess.py
Last active January 7, 2020 08:48
A minimal web server that runs shell commands, powered by Tornado and its Subprocess module
"""
A minimal web server that runs shell commands, powered by Tornado and its
Subprocess module. It does non-blocking IO and streams the response.
To start the server:
$ python tornado_subprocess.py
To send a shell command using httpie: