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
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
<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
#!/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
#!/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
# 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
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
// Supports a post as an example | |
$a = true; | |
// double aka nested ternary | |
echo isset($a)?'Outter':isset($a)?'Inner':'Else'; | |
// result "Inner" |
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
#!/bin/bash | |
############################################# | |
# AUTHOR: JONATHAN SCHWENN @JONSCHWENN # | |
# MAC MINI VAULT - MAC MINI COLOCATION # | |
# MACMINIVAULT.COM - @MACMINIVAULT # | |
# VERSION 1.07 RELEASE DATE MAY 20 2014 # | |
# DESC: THIS SCRIPT INSTALLS MySQL on OSX # | |
############################################# | |
#REQUIREMENTS: | |
# OS X 10.7 or newer |
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 | |
/* Check for presence of multiple keys in PHP using array_intersect_key | |
* @param $a : array of data to be checked | |
* @param $required : array of keys required | |
* @datamafia // -- Marc | |
*/ | |
// array to validate | |
$a = array( | |
'key1' => 'value1', |