Skip to content

Instantly share code, notes, and snippets.

View Ceasar's full-sized avatar

Ceasar Ceasar

View GitHub Profile
@Ceasar
Ceasar / local.py
Last active December 13, 2015 21:08
Extend fabric.api.local to run commands in the background.
import subprocess
import fabric
def local(command, capture=False, shell=False, bg=False):
if bg:
if capture:
with open("/dev/null", "w") as f:
subprocess.Popen(command.split(), stdout=f, shell=shell)
@Ceasar
Ceasar / ex1.py
Last active December 14, 2015 04:28
Experiments with scope in Python.
"""
Python scope is not dynamic.
"""
def foo():
print x
x = 0
@Ceasar
Ceasar / connect.py
Created April 3, 2013 00:54
Connect and stayed connected to AirPennNet.
import sys
import time
from sh import networksetup
DEVICE = 'en0'
NETWORK = u'AirPennNet'
def connect_to_network(network):
@Ceasar
Ceasar / send.rb
Created April 4, 2013 19:35
Send a text to a number from multiple numbers.
##
# sms_bomb
# ========
#
# Send a bunch of texts (from multiple numbers) to a target number.
#
# Installation
# ------------
#
# `gem install twilio-ruby`
@Ceasar
Ceasar / email_validator.py
Created April 22, 2013 01:48
Email Validator for wtforms using Django validator.
class Email(object):
message = 'Enter a valid email address.'
user_regex = re.compile(
r"(^[-!#$%&'*+/=?^_`{}|~0-9A-Z]+(\.[-!#$%&'*+/=?^_`{}|~0-9A-Z]+)*$" # dot-atom
r'|^"([\001-\010\013\014\016-\037!#-\[\]-\177]|\\[\001-\011\013\014\016-\177])*"$)', # quoted-string
re.IGNORECASE)
domain_regex = re.compile(
r'(?:[A-Z0-9](?:[A-Z0-9-]{0,61}[A-Z0-9])?\.)+(?:[A-Z]{2,6}\.?|[A-Z0-9-]{2,}\.?$)' # domain
# literal form, ipv4 address (SMTP 4.1.3)
r'|^\[(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}\]$',
@Ceasar
Ceasar / dotfiles.txt
Last active December 17, 2015 02:09
List of my dotfiles. For use with [dots](https://github.com/Ceasar/dots).
[email protected]:Ceasar/dot_zsh.git
[email protected]:Ceasar/dot_vim.git
[email protected]:Ceasar/dot_gitconfig.git
[email protected]:Ceasar/dotfiles.git
# Start postgres
alias pgstart='pg_ctl -l $PGDATA/server.log start'
# Stop postgres
alias pgstop='pg_ctl stop -m fast'
# Postgres stuff
export PGDATA='/usr/local/var/postgres'
# Register a python project on pypi
# -*- coding: utf-8 -*-
"""
:copyright: (c) 2011 by Armin Ronacher.
:copyright: (c) 2011 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
import os
import sys
import unittest
@Ceasar
Ceasar / primes.py
Created May 29, 2013 07:06
Speed test!
import timeit
setup = """
def primes(n):
'''Get all primes up to n.'''
if n < 2:
return []
nums = range(n)
sieve = set(xrange(2, n))
@Ceasar
Ceasar / first_principles.py
Created May 30, 2013 02:44
Works limitedly.
"""
"""
import inspect
import re
import pprint
FUNCTION_PATTERN = re.compile(".*\s((\.|\w)+)\(")