Skip to content

Instantly share code, notes, and snippets.

@jamalex
jamalex / gist:5997735
Created July 15, 2013 05:46
Counter-example to the two (otherwise very good) generalizations about Python that "assignment never makes new values, and it never copies data" and "Lots of Python data structures [e.g. object attributes] hold values, and each of those is a reference. All of the rules here about names apply exactly the same to any of these references." (see htt…
from copy import deepcopy
class MagicSetter(object):
def __setattr__(self, name, value):
super(MagicSetter, self).__setattr__(name, deepcopy(value))
m = MagicSetter()
m.a = ["this", "is", "the", "original", "list"]
"^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:/\S*)?$"
@jamalex
jamalex / gist:96123943baff9b3e7362
Created February 11, 2015 00:38
New videos and exercises between versions 0.12 and 0.13 of KA Lite
old_vids = set(["C-2Ln0pK3kY", "01c12NaUQDw", "ZD8THEz18gc", "5lmHzAHbtzg", "qVPtT8CX1eM", "ER49EweKwW8", "gzm-uhj06q8", "EA0LkCkvUeU", "TEfyIsDRGCk", "1C4ETKeTMq8", "LXi5FUMNTjE", "GW8ZPjGlk24", "_NWc3C3cTNA", "vAW9t5uBr08", "EvvxBdNIUeQ", "hGMwMlksZlM", "8GhjZn2W8ns", "-FtlH4svqx4", "ouAFk0Jy6TY", "Qp87Z4m8R-w", "wBCowBiXV7A", "MNUVuZu6heA", "HwSszh3L358", "W2NnNKtquaE", "P6PEf9WtEvs", "0CIn1_M-BoY", "nLY2bzRfQyo", "RouNXdkC0do", "KRFiAlo7t1E", "3cVSSiuiwsQ", "lOIP_Z_-0Hs", "CDvPPsB3nEM", "TErJ-Yr67BI", "M_ADc9jkBig", "TbaltFbJ3wE", "H5w55UbIZTw", "uqyLOuAzbvo", "-sA-vI2a2mM", "N06Jy-gQog8", "VrflZifKIuw", "z45UEiPaE8c", "QkepM8Vv3kw", "Sc6zc8KR_NU", "a-e8fzqv3CE", "I8BLj7cRM7c", "47JRs6hF_ic", "cTveNRjWQYo", "73eSiVcg4tQ", "9M-B5qU7ezY", "LhrGS4-Dd9I", "V7H1oUHXPkg", "EKKe7DBZVhI", "SZF5K8epWko", "Ncg1HB5uVLc", "Eh0j5nHhS6I", "h72iwhmB6zc", "DK1lCc9b7bg", "Y6JsEja15Vk", "kGrk6V8tWDY", "-h3Oqhl8fPg", "0isM0GF-rMI", "vbGwcvXgDlg", "NIG3l8oWKYE", "tbQ_7zvRoN4", "oUgDaEwMbiU", "aOSlXuDO4UU", "3zU90x0OZ0Y", "12
@jamalex
jamalex / dj.py
Created April 15, 2015 04:14
Handlebars.js vs Django templates benchmark
import time
from django.template import Template, Context
from django.conf import settings
settings.configure()
source = """<p>Hello, my name is {{name}}. I am from {{hometown}}. I have {{kids|length}} kids:</p>
<ul>{% for kid in kids %}<li>{{kid.name}} is {{kid.age}}</li>{% endfor %}</ul>"""
import requests
import tempfile
from bs4 import BeautifulSoup
from ricecooker.classes.nodes import ChannelNode, HTML5AppNode, TopicNode
from ricecooker.classes.files import HTMLZipFile, ThumbnailFile
from ricecooker.utils.caching import CacheForeverHeuristic, FileCache, CacheControlAdapter, InvalidatingCacheControlAdapter
from ricecooker.utils.html import download_file
from ricecooker.utils.zip import create_predictable_zip
import smpplib2.gsm
import smpplib2.client
import smpplib2.consts
import smpplib2.exceptions
# TODO: update these based on the address/credentials for the SCSM server
SMSC_ADDRESS = '127.0.0.1'
SMSC_PORT = 1234
SMSC_SYSTEM_ID = 'pavel'
SMSC_PASSWORD = 'wpsd'
@jamalex
jamalex / notion_task_manager.py
Created January 17, 2019 07:14
Notion task manager toy example
import datetime
import random
import time
from multiprocessing import Lock
from notion.client import *
from notion.block import *
mutex = Lock()
The Hangout on Air is not yet active. Please try again after 8am on Monday.
import json
import logging
import math
from contextlib import contextmanager
from django.core.management import call_command
from django.core.management.base import CommandError
from django.db import transaction
from morango.models import Filter
from morango.models import InstanceIDModel