Skip to content

Instantly share code, notes, and snippets.

@devdave
devdave / Doctrin2Search.php
Created Jun 21, 2011
Semi-dynamic Doctrine2 search function
View Doctrin2Search.php
<?php
function searchCriteria($criteria){
$cleanCritera = array();
foreach($criteria as $key => $value){
if( isset( $this->_class->fieldNames[$key] ) && !empty($value) ){
$cleanCritera[$key] = $value;
}
}
if(empty($cleanCritera)){
@devdave
devdave / wtf.php
Created Jun 22, 2011
I am in hell
View wtf.php
<?php
class Parent {
public $auto_render = true;
public function after(){
echo ($this->auto_render ? "true" : "false"), \n;
}
}
@devdave
devdave / metaclass_servicebus.py
Created Aug 26, 2011
Proof of concept for tying a metaclass auto-decorator with a service bus
View metaclass_servicebus.py
from collections import defaultdict
from functools import wraps
decoratedCalls = defaultdict(list)
def call(name, *args, **kwargs):
print name, args, kwargs
if name in decoratedCalls:
for cb in decoratedCalls[name]:
cb(*args, **kwargs)
@devdave
devdave / alternative.py
Created Oct 2, 2011
Reference twisted web example from Jcalderone's tutorials to using txWeb
View alternative.py
from txweb.core import Site
#from twisted.web.resource import Resource
from twisted.internet import reactor
import cgi
class Root(object):
def form(self, request):
View userevent.py
from collections import namedtuple
from twisted.internet.defer import Deferred
UserEvent = namedtuple("UserEvent", "subject, args, kwargs")
class UserEventStack(object):
def __init__(self, user):
self.events = []
@devdave
devdave / form_test.py
Created Dec 13, 2011
Flask HTML form array inputs
View form_test.py
from flask import Flask
from flask import request
app = Flask(__name__)
#Normally this would be an external file like object, but here
#it's inlined
FORM_PAGE = """
<html>
<head>
<title>Flask Form</title>
@devdave
devdave / visitor.py
Created Jan 12, 2012
Pynarcissus visitor like parser
View visitor.py
from pynarcissus import jsparser
from collections import defaultdict
class Visitor(object):
CHILD_ATTRS = ['thenPart', 'elsePart', 'expression', 'body', 'initializer']
def __init__(self, filepath):
self.filepath = filepath
#List of functions by line # and set of names
@devdave
devdave / visitor.py
Created Jan 13, 2012
Truncated base visitor class
View visitor.py
class Visitor(object):
CHILD_ATTRS = ['value', 'thenPart', 'elsePart', 'expression', 'body','exception', 'initializer', 'tryBlock', 'condition','update', 'iterator', 'object', 'setup', 'discriminant', 'finallyBlock', 'tryBlock', 'varDecl', 'target']
def __init__(self, filepath):
self.filepath = filepath
#List of functions by line # and set of names
self.functions = defaultdict(set)
with open(filepath) as myFile:
self.source = myFile.read()
@devdave
devdave / cleanit.py
Created Mar 20, 2012
Hack to remove another hack
View cleanit.py
#!/usr/bin/env python
import re
import sys
import os
path = os.path
CLEAN_RE = re.compile(r"""^\<\?php\s\/\*\*\/\seval\(base64_decode\("[^"]*"\)\);\?>""")
def inspectFile(fullpath):
try:
@devdave
devdave / build.sh
Created Apr 24, 2012 — forked from jonah-williams/build.sh
Command line iOS project builds and over-the-air distribution
View build.sh
#!/bin/bash
# https://gist.github.com/949831
# http://blog.carbonfive.com/2011/05/04/automated-ad-hoc-builds-using-xcode-4/
# command line OTA distribution references and examples
# http://nachbaur.com/blog/how-to-automate-your-iphone-app-builds-with-hudson
# http://nachbaur.com/blog/building-ios-apps-for-over-the-air-adhoc-distribution
# http://blog.octo.com/en/automating-over-the-air-deployment-for-iphone/
# http://www.neat.io/posts/2010/10/27/automated-ota-ios-app-distribution.html