Skip to content

Instantly share code, notes, and snippets.

@edelooff
edelooff / integrity_example.py
Created June 5, 2015 18:44
Catching and handling IntegrityError in SQLAlchemy
import sys
import sqlalchemy as sa
from sqlalchemy.exc import IntegrityError
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
base = declarative_base()
print 'SQLAlchemy version {}'.format(sa.__version__)
@PurpleBooth
PurpleBooth / README-Template.md
Last active June 18, 2025 21:40
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@fisadev
fisadev / work
Created December 3, 2015 14:57
A python script to launch my tmux things at once
#!/usr/bin/env python
# coding: utf-8
from os import system
PROJECT_PATH = 'path_to_your_project'
ACTIVATE_VENV = '. path_to_your_virtualenv/bin/activate'
def tmux(command):
@claymcleod
claymcleod / pycurses.py
Last active April 28, 2025 17:11
Python curses example
import sys,os
import curses
def draw_menu(stdscr):
k = 0
cursor_x = 0
cursor_y = 0
# Clear and refresh the screen for a blank canvas
stdscr.clear()
@APTy
APTy / multisig.py
Created January 30, 2016 01:46
two1 multisig
import two1.lib.bitcoin as bitcoin
from two1.lib.wallet import Wallet
wallet = Wallet()
# Collect public keys
p1_pubkey = wallet.get_payout_public_key()
p2_pubkey = wallet.get_change_public_key()
# Build multisig redeem script
@demoray
demoray / mytasks.py
Last active September 2, 2018 07:13
A custom complete method for luigi tasks that will re-run the task if any prerequisite task is newer
class MyTask(luigi.Task):
def complete(self):
def _get_last(outputs):
last = 0.0
for item in outputs:
if not item.exists():
continue
current = os.path.getmtime(item.path)
if current > last:
last = current
@drhanlau
drhanlau / main.py
Last active May 27, 2018 18:17
Observer
if __name__ == "__main__":
stock_watcher = Observable()
american_observer = AmericanStockMarket()
stock_watcher.register(american_observer)
stock_watcher.publish('KLSE Market Update', price='+0.5')
@chenjianjx
chenjianjx / start-celery-for-dev.py
Created March 10, 2016 10:45
A python script which starts celery worker and auto reload it when any code change happens.
'''
A python script which starts celery worker and auto reload it when any code change happens.
I did this because Celery worker's "--autoreload" option seems not working for a lot of people.
'''
import time
from watchdog.observers import Observer ##pip install watchdog
from watchdog.events import PatternMatchingEventHandler
import psutil ##pip install psutil
import os
@DamnedScholar
DamnedScholar / language-sampleGrammar.cson
Last active July 28, 2024 08:43
Grammar boilerplate with annotations.
# TextMate tutorial: http://manual.macromates.com/en/language_grammars
# Regex to convert keys to unquoted: '(include|match|captures|begin|end|beginCaptures|endCaptures|name|patterns|0|1|2|3|4|5|6|7|8|9|comment|fileTypes|scopeName|repository|contentName|firstLineMatch|foldingStartMarker|foldingStopMarker)':
scopeName: 'source.<scope>' # <scope> should be a short, unique indicator for the language ("js", "php", "c", etc.)
name: '<name>' # The title that will show up in grammar selection and on your status bar.
fileTypes: [ # An array of file extensions.
'txt'
'exif'
]