Skip to content

Instantly share code, notes, and snippets.

@mikeyk
mikeyk / redis_session_backend.py
Created April 8, 2011 18:01
A redis backend for Django Sessions, tested on Django 1.3+
from django.contrib.sessions.backends.base import SessionBase, CreateError
from django.conf import settings
from django.utils.encoding import force_unicode
import redis
class SessionStore(SessionBase):
""" Redis store for sessions"""
def __init__(self, session_key=None):
self.redis = redis.Redis(
@mikeyk
mikeyk / gist:1329319
Created October 31, 2011 22:56
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import pylibmc
import sys
r = redis.Redis(host = 'localhost', port = 6389)
mc = pylibmc.Client(['localhost:11222'])
@dergachev
dergachev / GIF-Screencast-OSX.md
Last active November 5, 2024 18:44
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@benselme
benselme / select2_selenium.py
Last active August 19, 2019 04:02
Simple helper class to use Select2 controls with Selenium Webdriver
from selenium.webdriver import ActionChains
class Select2(object):
def __init__(self, element):
self.browser = element.parent
self.replaced_element = element
self.element = browser.find_element_by_id(
's2id_{0}'.format(element.get_attribute('id')))
def click(self):
"""
This file contains code that, when run on Python 2.7.5 or earlier, creates
a string that should not exist: u'\Udeadbeef'. That's a single "character"
that's illegal in Python because it's outside the valid Unicode range.
It then uses it to crash various things in the Python standard library and
corrupt a database.
On Python 3... well, this file is full of syntax errors on Python 3. But
if you were to change the print statements and byte literals and stuff:

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@nsfyn55
nsfyn55 / gist:c1ca64e580f60a3f78a3
Last active August 29, 2015 14:20
Convert Timezone Aware Date to Timezone unaware UTC Equivalent
from dateutil.parser import parse
from pytz import utc
datestr = 'Fri, 24 Apr 2015 14:49:32 -0400'
dt = parse(datestr)
utc_dt = dt.astimezone(utc)
final = utc_dt.replace(tzinfo=None)
@nsfyn55
nsfyn55 / prob.py
Created June 16, 2015 20:36
Project Euler Problem 1
"""
if we list all the natural numbers below 10 that are multiples of 3 or 5, we get
3, 5, 6 and 9. The sum of these multiples is 23.
"""
cap = 1000
total = 0
for i in range(1,cap):
@karpathy
karpathy / min-char-rnn.py
Last active November 18, 2024 15:04
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@sotsugov
sotsugov / The Technical Interview Cheat Sheet.md
Last active November 27, 2018 15:38 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

Array

Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.