Skip to content

Instantly share code, notes, and snippets.

View jMyles's full-sized avatar

Justin Holmes jMyles

View GitHub Profile
@jMyles
jMyles / gist:7059961
Last active December 25, 2015 23:49
InterviewJet FizzBuzz. Replete with ugly list comprehension. I'm not looking for a job right now, but if you want to apply at InterviewJet and aren't in the mood to make a FizzBuzz for the eight millionth time, your troubles are over.
exclusive_boundry = 1000
multiples = [3, 5]
sum = 0
for candidate in range(exclusive_boundry):
if 0 in [candidate % multiple for multiple in multiples]:
sum += candidate
print sum
@jMyles
jMyles / search-for-reelio
Created December 20, 2013 19:16
The output of Selenium Builder exporting to Python/unittest after recording the activity of browsing to HackerNews and searching for "reelio."
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.common.action_chains import ActionChains
import time, unittest
def is_alert_present(wd):
try:
wd.switch_to_alert().text
return True
except:
return False
Title: Deprecate tap2deb and tap2rpm
Text:
tab2deb and tap2rpm are command-line utilities that create a shim over a .tap file, allowing it to be installed as an OS package (.deb or .rpm respectively).
Currently, a test (twisted.scripts.test.test_tap2deb.TestTap2DEB.test_basicOperation) fails in some situations, apparently because these utilities don't work properly in some specific OS configurations. For example, see https://twistedmatrix.com/trac/ticket/6920 (closed for other reasons).
It is not immediately obvious how widespread their use is, but exarkun advises deprecation. Another developer will need to weigh-in with a deprecation justification is one is to be provided.
'''
Mezzanine lets you inject fields on its own stock models using the EXTRA_MODEL_FIELDS setting.
However, as the Mezzanine docs point out (http://mezzanine.jupo.org/docs/model-customization.html#field-injection-caveats), there are some "caveats" regarding migrations.
Specifically, the migrations need to be placed in a local app even though they're applied to the Mezzanine models.
What's the proper way to do this in Django 1.7? I have a solution below that works, but it's obviously ugly.
'''
class Incident(models.Model):
owner = models.ForeignKey(User)
class IncidentData(models.Model):
key = models.CharField(max_length=255)
value = models.CharField(max_length=255)
incident = models.ForeignKey(Incident)
## Or, if you want to have manager-level control for the IncidentData:
from hendrix.contrib.async import do_async
def my_view(request):
# blah blah blah, Django stuff
with do_async(pubsub_id) as reporter:
for long_thing in long_things:
result_of_long_thing = long_thing()
from hendrix.contrib.async import do_async
def my_view(request):
# blah blah blah, Django stuff
@do_async.after_response(pubsub_id):
def function_name_that_becomes_thread_name(reporter):
for long_thing in long_things:
@jMyles
jMyles / gist:804ad85a85cb26e5d762
Created April 22, 2015 21:50
maybe in python
def tell_me_the_answer(question):
if question.determine_truth:
return True
if not question.determine_truth:
return False
## Conceptually, why not?
if question.dont_know_yet:
@jMyles
jMyles / gist:56810d1dcdd545c725dc
Last active August 29, 2015 14:21
Literal / Expressive - more DRY?
# Which is more DRY..
# Option 1
x = 1
y = '1'
z = 1.0
# Or option 2
x = 1
y = str(x)
@jMyles
jMyles / gist:53065e3611d7d1b86753
Created May 27, 2015 17:25
theCommApp preview #1
# The API:
class BirthLine(PhoneLine):
greeting = "Thanks for calling Chelsea and Justin's birth information line."
disposition = [ConferenceHoldingPattern()]
features = [BirthCallBlast]
nobody_home = Voicemail