Python 3.6.1 (default, Apr 12 2017, 14:04:19)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> if 0:
... print("0 is truthy")
... else:
... print("0 is falsey")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from optparse import OptionParser | |
import re | |
# The book Programming Pearls has an excercise to code | |
# a simple algorithm for taking numbers pressed on a | |
# phone keypad and returning the names from a directory | |
# that the caller may have been looking for. The book | |
# is really aimed at C and C++, but I'm doing some of these | |
# in Python since that's what I mostly work in these days | |
# and am building my skills in. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class InlineToggleMixIn(object): | |
""" | |
Allows details=<resource> querystring param to toggle whether to return resource uri or full details | |
""" | |
# based on handy dehydrate_related from | |
# http://chrismeyers.org/2012/06/25/tastypie-inline-aka-nested-fulltrue-embedded-relationship-dynamically-via-get-parameter/ | |
# Be careful not to create an infinite loop from having multiple resources that reference each other using this | |
# and requesting details on both of them | |
def dehydrate_related(self, bundle, related_resource): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
// lots of other stuff in the full code | |
var compiled_templates = new Object(); | |
var ALBUMLIST = 'album-list.js'; // real code has several more of these. It's the filename of a handlebars.js template | |
function getTemplateAjax(file) { | |
// downloads a handlebars.js template via ajax and sticks it into the cache object after compiling | |
var template; // this could really go down in the success function | |
return $.ajax({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
The basic solution to http://www.reddit.com/r/dailyprogrammer/comments/149kec/1242012_challenge_114_easy_word_ladder_steps/ | |
in Python. Neither of the bonuses at the moment | |
""" | |
from sys import argv | |
testword = argv[1] | |
# wordlist from http://pastebin.com/zY4Xt7iB | |
for word in open('114_wordlist.txt', 'r'): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Child do | |
use MyApp.Web, :model | |
schema "child" do | |
field :name, :string | |
field :description, :string | |
belongs_to :event, MyApp.Parent | |
timestamps | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# from https://github.com/influxdata/influxdb/issues/4155#issuecomment-268719194 | |
SELECT * INTO new_name FROM old_name | |
DROP MEASUREMENT old_name |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Raspberry pi touchscreens get blanked and then later the backlight turned off. | |
When in X of some sort, taps on the screen can turn it back on. When in a console | |
taps on the touchscreen are not seen and the display stays asleep. | |
This script polls mouse inputs in /dev/input for any action on the raspberry pi touchscreen | |
if there is action, update the file which controls the backlight power to | |
turn the backlight back on. | |
This should be tweaked more to not be constantly writing to the bl_power file, possibly monitor |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
This is an example of how Python's Graphene library behaves. This can result in `self` not being what you expect, particularly | |
when using graphene-django and `self` on your graphene resolver object is the underlying django model | |
""" | |
class A: | |
def foo(self): | |
print("This is the foo() method on an object of class", type(self)) | |
class B: | |
pass |
OlderNewer