Skip to content

Instantly share code, notes, and snippets.

View stevejalim's full-sized avatar
❤️
Pro tip: be kind

Steve Jalim stevejalim

❤️
Pro tip: be kind
View GitHub Profile
@stevejalim
stevejalim / patch_with_reload.py
Created December 21, 2018 16:00 — forked from Geekfish/patch_with_reload.py
Same as patch, but allows you to pass a module object which will be reloaded when entering/leaving the context.
import imp
from functools import partial
from mock.mock import _patch, _get_target, DEFAULT
class PatchWithReload(_patch):
def __init__(self, module_to_reload, *args, **kwargs):
self.module_to_reload = module_to_reload
super(PatchWithReload, self).__init__(*args, **kwargs)
@stevejalim
stevejalim / bulk.py
Created June 29, 2018 19:51 — forked from danfairs/bulk.py
Bulk utilities
"""
Utilities for working with bulk data and batches.
"""
import itertools
def batches(items, batch_size=500):
"""
Given an iterable of items and a batch size, yield individual lists
of items of maximum length `batch_size`.
@stevejalim
stevejalim / keybase.md
Created February 26, 2016 09:29
keybase.md

Keybase proof

I hereby claim:

  • I am stevejalim on github.
  • I am stevejalim (https://keybase.io/stevejalim) on keybase.
  • I have a public key whose fingerprint is B2A9 6BCD F133 CD6B 4CE6 087E EEE6 B419 4EB8 B898

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am stevejalim on github.
  • I am stevejalim (https://keybase.io/stevejalim) on keybase.
  • I have a public key whose fingerprint is F1D5 A200 C1A7 87F7 9F0C 44BA BB31 E81E DEC6 2004

To claim this, I am signing this object:

This is a simple python script that can be used to 'listen' to the Twitter Stream API, tracking certain words, and then forwarding those on to HipChat.

It's useful if you spend a lot of time in HipChat, and want to monitor tweets at the same time.

You'll need to set up a Twitter application, and also get a valid oauth token using that app - go to https://apps.twitter.com/app/new and follow the

### Keybase proof
I hereby claim:
* I am stevejalim on github.
* I am stevejalim (https://keybase.io/stevejalim) on keybase.
* I have a public key whose fingerprint is 3051 A182 1392 3039 6FC5 C71B CFAE A0DF 26AF C63D
To claim this, I am signing this object:
// How to upgrade your users passwords in the DB without their intervention
//
// SHA-1 isn't strong enough to hash passwords with, but lots of people have a
// whole bunch of SHA-1'd passwords because they thought it was. You could use
// bcrypt or scrypt, but maybe in two years' time someone will tell you that's
// also not strong enough, and you'll want to upgrade.
//
// This sample demonstrates how you can remove weak password hashes from your
// user database, without needing the user to enter their password.
@stevejalim
stevejalim / gist:2644805
Created May 9, 2012 14:19
South migration plan for collaborative working (by @nealtodd)
Best practice summary
==================
1. Always use orm when referencing models if you add data migration code to a schemamigration or do a datamigration.
2. If using a feature branch, do the migration on the develop branch and merge it into the feature branch if that migration is safe to do on develop (e.g. adds a new model or a benign field) with minimal code changes. This will avoid the need to do out-of-sequence merging.
3. If you have to do the migration on the branch claim the next migration number and, as usual, let the other developers know it's yours.
4. After finishing the feature if no higher numbered migrations exist on develop you can just do a normal migrate.
5. If there are higher numbered migrations:
a. do a migrate with the --merge flag
b. do a schemamigration with the --empty flag
6. Continue with schemamigrations as normal using the --auto flag
@stevejalim
stevejalim / gist:2635496
Created May 8, 2012 14:21
Django forms CSSField
import re
from django import forms
def validate_CSS_color(value):
"""Checks the value is a valid CSS hex colour string"""
hit = re.match("(?i)^#([0-9a-f]{3}|[0-9a-f]{6})$", value)
return bool(hit)
@stevejalim
stevejalim / gist:2478912
Created April 24, 2012 11:33
Django StrongPasswordField
import re
from django import forms
def is_password_strong_enough(value):
"""
"All passwords should be:
10+ characters long
contain at least one upper-case character
contain at least one lower-case character
contain at least one numeric digit