Skip to content

Instantly share code, notes, and snippets.

View datamafia's full-sized avatar
☠️
not here

" and 1=1 " datamafia

☠️
not here
  • At Desk
View GitHub Profile
@datamafia
datamafia / gist:f74ea05dd687aefd5da8
Created December 7, 2014 05:00
Dynamically call method using a variable
class CallMe: # Class
def __init__(self):
return
def App(self): # Method one
print 'App'
def Foo(self): # Method two
print 'Foo'
@datamafia
datamafia / playing_with_kwargs.py
Created December 11, 2014 19:40
A few ways to handle kwargs.
# 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()
@datamafia
datamafia / gist:baba53f5de148fd90c0f
Created January 10, 2015 00:17
Group match and replace to use liquid and similar template systems to document syntax.
#!/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
@datamafia
datamafia / notification.py
Created January 27, 2015 20:47
Global Notification Object -work in progress-
#!/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',
<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>
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;
@datamafia
datamafia / switch_and_eval_in_php.php
Created February 8, 2015 20:13
Using switch statement and additional evaluation in php super short demo.
<?
// Switch statment + additional eval
ini_set('display_errors',1);
$arr = array(
'match',
'other'
);
x($arr);
@datamafia
datamafia / repr_and_haphazard.py
Created February 13, 2015 15:34
# Fast and haphazard introduction to repr in Python supports #twitter
#!/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'
@datamafia
datamafia / mini_subclass.py
Created February 22, 2015 18:37
Minimal proto for subclass in Python (social media)
#!/usr/bin/env python
class A(object):
var = 'A'
def __init__(self):
self.test()
def test(self):
print 'Class A: '+self.var
@datamafia
datamafia / worpress_dev.php
Created March 5, 2015 16:26
Wordpress development script for previews
<?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