Skip to content

Instantly share code, notes, and snippets.

@leth
leth / index.php
Created April 21, 2011 14:52
How to use the Kohana framework as a library
<?php
$content = 'Hello World';
?>
<html>
<head>
<title>Demo page</title>
</head>
<body>
<?php echo $content; ?>
@leth
leth / gist:1142925
Created August 12, 2011 20:29
An example autoloader
<?php
function jelly_tests_autoload($classname)
{
$filename = __DIR__.'/tests/classes/'. strtolower(str_replace($classname, '_', '/'))).EXT;
if (file_exists($filename))
require_once $filename;
}
if (TRUE /* If testing is enabled */)
@leth
leth / enum.py
Created May 19, 2012 18:24
This is my enum. There are many like it, but this one is mine.
import inspect
class Instance(object):
"""docstring for Instance"""
def __init__(self, *args, **kwargs):
self.args = args
self.kwargs = kwargs
class ValueInstance(object):
@leth
leth / gist:3940766
Created October 23, 2012 18:51
Virtualbox differencing disks for Vagrant

Summary

  • Detach disk from VM
  • Clone VM (fast!)
  • Attach disk to new VM in 'multiattach' mode (On attaching, virtualbox creates a new differencing image tied to original disk)
  • ...
  • Profit!

Status/Notes

@leth
leth / libpython.py
Last active April 10, 2022 06:13
Working python frames in gdb for production python interpreters
#!/usr/bin/python
'''
From gdb 7 onwards, gdb's build can be configured --with-python, allowing gdb
to be extended with Python code e.g. for library-specific data visualizations,
such as for the C++ STL types. Documentation on this API can be seen at:
http://sourceware.org/gdb/current/onlinedocs/gdb/Python-API.html
This python module deals with the case when the process being debugged (the
"inferior process" in gdb parlance) is itself python, or more specifically,
@leth
leth / gist:9291261
Last active August 29, 2015 13:56 — forked from sloria/gist:5895687
f = open('file.txt', 'w')
f.write('hi')
f.close()
# Better
with open('file.txt', 'w') as f:
f.write('hi')
with pytest.raises(ValueError):
int('hi')
@leth
leth / main.go
Created April 8, 2014 19:32
Example Mac OSX SDL app (avoids NSInternalInconsistencyException)
package main
/*
#import <dlfcn.h>
int
PreInit() {
void* cocoa_lib;
cocoa_lib = dlopen( "/System/Library/Frameworks/Cocoa.framework/Cocoa", RTLD_LAZY );
@leth
leth / changes
Created August 8, 2014 15:40
ansible jinja2 escaping speedup
diff --git c/lib/ansible/utils/__init__.py i/lib/ansible/utils/__init__.py
index 5da39ac..696f1a7 100644
--- c/lib/ansible/utils/__init__.py
+++ i/lib/ansible/utils/__init__.py
@@ -33,7 +33,7 @@ from ansible.module_utils.splitter import split_args, unquote
import ansible.constants as C
import ast
import time
-import StringIO
+import cStringIO
@leth
leth / bench.py
Created August 9, 2014 22:42
_clean_data benchmarking
import os
import re
import StringIO
import cStringIO
import contextlib
# caching the compilation of the regex used
# to check for lookup calls within data
LOOKUP_REGEX=re.compile(r'lookup\s*\(')
import weakref
import threading
from twisted.python.threadpool import ThreadPool
from crochet import EventualResult
_blocked_pool_threads = weakref.WeakKeyDictionary()
_orig_pool_limits = weakref.WeakKeyDictionary()
_originals = {}