Skip to content

Instantly share code, notes, and snippets.

@obeattie
obeattie / db_utils.py
Created October 14, 2009 12:51
Exposes SQLAlchemy's sessions and transactions as context managers (so they will be managed automatically inside blocks), and also provides a transaction decorator, which wraps an entire function in a transaction
"""Utilities for managing database sessions."""
from __future__ import with_statement
import contextlib
import functools
@contextlib.contextmanager
def temp_session(session_cls, **kwargs):
"""Quick and dirty context manager that provides a temporary Session object
to the nested block. The session is always closed at the end of the block.
@gregorynicholas
gregorynicholas / .inputrc
Last active April 19, 2024 04:10
OSX .inputrc to make terminal way better. and by better i mean i'm naked
"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": history-search-backward
"\e[6~": history-search-forward
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
@godbyk
godbyk / fullwidth-minipage
Created March 16, 2012 21:47
Minipage similar to full-width environment -- with nice spacing
\documentclass{tufte-handout}
%% Just draws a baseline grid on the page
\usepackage{pagegrid}
\pagegridsetup{
top-left,
step=\baselineskip,
arrowlength=1pt,
}
% End baseline grid code
#!/usr/bin/python
from selenium import webdriver
import unittest, time, re
from random import choice
correctanswers = []
def tryitnow ():
# Copy and paste the module url below, including the key:
@Fuuzetsu
Fuuzetsu / hackagedocs
Last active December 13, 2022 22:40
Script for generating and uploading missing documentation for your Hackage packages. Now with fixed package links and contents page.
#!/usr/bin/env bash
cabal configure && cabal build && cabal haddock --hyperlink-source \
--html-location='/package/$pkg-$version/docs' \
--contents-location='/package/$pkg'
S=$?
if [ "${S}" -eq "0" ]; then
cd "dist/doc/html"
DDIR="${1}-${2}-docs"
cp -r "${1}" "${DDIR}" && tar -c -v -z --format=ustar -f "${DDIR}.tar.gz" "${DDIR}"
CS=$?
@lifuzu
lifuzu / .gitconfig
Created March 11, 2014 17:09
Three levels of GIT config
# There are 3 levels of git config; project, global and system.
# project: Project configs are only available for the current project and stored in .git/config in the project's directory.
# global: Global configs are available for all projects for the current user and stored in ~/.gitconfig.
# system: System configs are available for all the users/projects and stored in /etc/gitconfig.
# Create a project specific config, you have to execute this under the project's directory.
$ git config user.name "John Doe"
# Create a global config
@lkilcher
lkilcher / Segmented Plot as Func.md
Last active August 29, 2015 14:10 — forked from orome/Segmented Plot
Segmented Plot

This file sets the title of this gist.

This gist gives an example of how to implement SO question 27138751 by defining a 'segment_plot' function.

@erantapaa
erantapaa / enigma.lhs
Last active May 10, 2021 15:04
enigma in Haskell
Emulating an Enigma machine
===
In this gist I'll go over the development of an Enigma machine encoder
in Haskell.
Here are some useful background info about how the Enigma machine works:
- Enigma Simulator: http://enigmaco.de/enigma/enigma.html
- "How Enigma Machines Work" http://enigma.louisedade.co.uk/howitworks.html
@erikbern
erikbern / install-tensorflow.sh
Last active June 26, 2023 00:40
Installing TensorFlow on EC2
# Note – this is not a bash script (some of the steps require reboot)
# I named it .sh just so Github does correct syntax highlighting.
#
# This is also available as an AMI in us-east-1 (virginia): ami-cf5028a5
#
# The CUDA part is mostly based on this excellent blog post:
# http://tleyden.github.io/blog/2014/10/25/cuda-6-dot-5-on-aws-gpu-instance-running-ubuntu-14-dot-04/
# Install various packages
sudo apt-get update
@lukas-h
lukas-h / license-badges.md
Last active July 25, 2024 22:25
Markdown License Badges for your Project

Markdown License badges

Collection of License badges for your Project's README file.
This list includes the most common open source and open data licenses.
Easily copy and paste the code under the badges into your Markdown files.

Notes

  • The badges do not fully replace the license informations for your projects, they are only emblems for the README, that the user can see the License at first glance.

Translations: (No guarantee that the translations are up-to-date)