Skip to content

Instantly share code, notes, and snippets.

@umbrae
umbrae / genders.sql
Created January 17, 2012 19:00
Roughly detect gender by first name in SQL
-- This table is useful for rough statistics based on gender
-- Don't consider it scientific in any way.
--
-- Example use:
-- select COALESCE(
-- (SELECT gender
-- FROM gender_types
-- WHERE name=users.first_name
-- LIMIT 1),
-- 'U') gender_type, count(*)
@umbrae
umbrae / gist:3658512
Created September 6, 2012 16:57
Sample image upload for Etsy Listings
<?php
define('OAUTH_CONSUMER_KEY', 'YOUR_CONSUMER_KEY_HERE');
define('OAUTH_CONSUMER_SECRET', 'YOUR_CONSUMER_SECRET_HERE');
$listing_id="ID_OF_LISTING_THAT_YOU_OWN_HERE";
$filename="FILENAME_THAT_EXISTS_ON_THE_FILESYSTEM_HERE.JPG";
$mimetype="image/jpeg";
$access_token="ACCESS_TOKEN_YOU_HAVE_AUTHENTICATED_WITH_HERE";
$access_token_secret="ACCESS_SECRET_THAT_YOU_HAVE_AUTHENTICATED_WITH_HERE";
// You must define the constants OAUTH_CONSUMER_KEY and OAUTH_CONSUMER_SECRET
@umbrae
umbrae / approx-queryset.py
Created July 6, 2011 20:32
Adding MySQL detection to approximate count queryset, taken from here: http://www.tablix.org/~avian/blog/archives/2011/07/django_admin_with_large_tables/
from django.db import connections
from django.db.models.query import QuerySet
class ApproxCountQuerySet(QuerySet):
"""Counting all rows is very expensive on large Innodb tables. This
is a replacement for QuerySet that returns an approximation if count()
is called with no additional constraints. In all other cases it should
behave exactly as QuerySet.
Only works with MySQL. Behaves normally for all other engines.
@umbrae
umbrae / .block
Last active August 19, 2019 00:13 — forked from danse/.block
Polar Clock (Duration Mode)
license: gpl-3.0
@umbrae
umbrae / gist:1683249
Created January 26, 2012 15:22
Speed comparison of finding if a digit exists in a string, in python.
>>> cmd = """
... for c in 'xdtwkeltjwlkejt7wthwk89lk':
... if c.isdigit():
... break;
... """
>>>
>>> timeit.Timer(cmd).timeit()
2.1454498767852783
>>>
>>>
From: umbrae@gmail.com [mailto:umbrae@gmail.com]
Sent: Friday, August 26, 2005 8:05 AM
To: Secure@macromedia.com
Subject: [Security Issue] [The encryption algorithm]
The following information was submitted on the Security Issue Report
Form :
Name: Umbrae
@umbrae
umbrae / gist:5624368
Last active December 17, 2015 14:29
What if Politicians could Speak without Reproach?

I had a crazy idea tonight. I've had a lot of these lately that I don't do much with, so I wanted to write about it.

I was walking home, listening to the most recent This American Life , on the politics of the climate change debate. In one of the scenes, the former Congressional Representative Bob Inglis is explaining that there are many Republican politicians who believe in the science of climate change, but simply cannot say a word about it publicly because to do so would be political suicide.