Skip to content

Instantly share code, notes, and snippets.

#! /usr/bin/env clj
(ns foo)
(prn "Hello")
neutron!ieure:~/Projects/clojure/foo/src$ ./foo.clj
"Hello"
Exception in thread "main" java.io.FileNotFoundException: --./foo.clj (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at clojure.lang.Compiler.loadFile(Compiler.java:4821)
at clojure.main$load_script__5833.invoke(main.clj:206)
at clojure.main$init_opt__5836.invoke(main.clj:211)
at clojure.main$initialize__5846.invoke(main.clj:239)
(defun php-lint ()
"Performs a PHP lint-check on the current file."
(interactive)
(require 'compile)
(let* ((compilation-error-regexp-alist '(php))
(compilation-error-regexp-alist-alist ())
(tramp (tramp-tramp-file-p (buffer-file-name)))
(file (or (and tramp
(aref (tramp-dissect-file-name (buffer-file-name)) 3))
(buffer-file-name))))
@ieure
ieure / star.py
Created September 14, 2009 20:23
Functional version of the Python */** operators
# -*- coding: utf-8 -*-
#
# Author: Ian Eure <ian@digg.com>
#
"""Star function."""
from functools import partial
import unittest
@ieure
ieure / retry.py
Created September 29, 2009 23:49
from functools import partial
from itertools import imap
from operator import or_
def retry(ntimes=3, ignore=None, trap=None):
"""Retry an operation some number of times.
The ignore and trap arguments may be a sequence (or a single)
exception class. If the decorated function raises an exception
matching ignore, it will be raised.
# -*- coding: utf-8 -*-
# foo()'s a_value is unmodified.
def foo():
a_value = "Hello"
def bar():
a_value = "Goodbye"
bar()
# -*- coding: utf-8 -*-
import threading
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
engine = create_engine("mysql://testing:testing@10.0.0.1/testing",
pool_size=20, strategy="threadlocal")
Session = scoped_session(sessionmaker(bind=engine))
# -*- coding: utf-8 -*-
import threading
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, scoped_session
def query():
engine = create_engine("mysql://testing:testing@10.0.0.1/testing",
pool_size=20, strategy="threadlocal")
Session = scoped_session(sessionmaker(bind=engine))
@ieure
ieure / save.py
Created November 16, 2009 22:28
from contextlib import contextmanager
@contextmanager
def save(obj, attrs=None):
"""Save attributes of an object, then restore them.
Example:
import breakfast
with save(breakfast, ('eggs', 'bacon')):
breakfast.Eggs = lambda: "Eggs"
<?php
error_reporting(E_ALL | E_STRICT);
class Foo
{
public static function test()
{
echo "Hi!\n";
}