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 CallMe: # Class | |
def __init__(self): | |
return | |
def App(self): # Method one | |
print 'App' | |
def Foo(self): # Method two | |
print 'Foo' |
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
# A few ways to handle kwargs, notes form the field. | |
class simple(object): | |
def __init__(self, **kwargs): | |
print 'simple.__init__()' | |
print 'Kwargs :' | |
print kwargs | |
t = simple() |
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
#!/usr/bin/python | |
# Problem : Need to present {{, }}, {%, and %} in html document without | |
# triggering parser | |
# Solution : Simple python script to open a file and replace {{,}},{& and %} with | |
# HTML escaped characters inside pre tags. Key to documenting liquid and other | |
# template systems using that very template system for rendering | |
# Handles newline as a character / able to operate w/line breaks | |
# datamafia.com likes Python | |
import re |
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
#!/usr/bin/python | |
# http://datamafia.com | |
from time import gmtime, strftime | |
class notification: | |
notif = {} # container for all messages | |
summary_order = ( # list of notif types + order. Override as needed. | |
'log', | |
'user_good', |
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
<p> | |
My programming language of preference is python for the simple reason that I feel I write better code faster with it then I do with other languages. However also has a lot of nice tricks and idioms to do things well. And partly as a reminder to myself to use them, and partly because I thought this might be of general interest I have put together this collection of some of my favourite idioms. I am also putting this on <a href="https://gist.github.com/codefisher/9d7993ddbf404c505128">gist.github.com</a> so that anyone that wants to contribute there own things can, and I will try and keep this post up to date. | |
</p> | |
<h2>enumerate</h2> | |
<p> | |
A fairly common thing to do is loop over a list while also keeping track of what index we are up to. Now we could use a <code>count</code> variable, but python gives us a nicer syntax for this with the <code>enumerate()</code> function. | |
<script src="https://gist.github.com/codefisher/9d7993ddbf404c505128.js?file=enumerate.py"></script> |
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
var scimoz = ko.views.manager.currentView.scimoz, | |
savedPos = scimoz.currentPos, | |
savedLinePos = scimoz.firstVisibleLine; | |
try { | |
scimoz.text = scimoz.text.replace(/\t/gm, " "); | |
scimoz.gotoPos(savedPos); | |
scimoz.lineScroll(0, savedLinePos-scimoz.firstVisibleLine); | |
} catch(e) { | |
return true; |
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
<? | |
// Switch statment + additional eval | |
ini_set('display_errors',1); | |
$arr = array( | |
'match', | |
'other' | |
); | |
x($arr); |
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
#!/usr/bin/env python | |
# Fast and haphazard introduction | |
# to repr in Python | |
g = 'x' | |
print(g) # x | |
# reprESENTATION is if... (terminal) | |
print(repr(g)) # 'x' | |
repr = 'y' |
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
#!/usr/bin/env python | |
class A(object): | |
var = 'A' | |
def __init__(self): | |
self.test() | |
def test(self): | |
print 'Class A: '+self.var |
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
<?php | |
/* | |
Install this in your theme header.php as the first statement | |
(next line right after the <?php opening tag) | |
Change $magic_word to what ever variable you want to use, | |
default is "preview" | |
To use this, go to yoursite.com?preview and a session will | |
be created and access to the site will last as long as the |