Skip to content

Instantly share code, notes, and snippets.

@monzee
monzee / Extend.php
Created October 30, 2009 17:43
Zend_View template inheritance
<?php
/**
* Calls the render() method of the Extend view helper if needed
*
* @author Mon Zafra <monzee at gmail>
* @copyright (c)2009 Mon Zafra
* @category Mz
* @package
* @license http://mz-project.googlecode.com/svn/trunk/LICENSE MIT License
@monzee
monzee / Bootstrap.php
Created February 9, 2010 02:06
Catching early exceptions
<?php
/* APPLICATION_PATH/Bootstrap.php */
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
protected $_appNamespace = 'Application_';
protected function _initFoo()
{
throw new BadMethodCallException('foo!');
@monzee
monzee / gist:2572256
Created May 1, 2012 23:11 — forked from isa/gist:2571012
Convert in less than 30 lines
from __future__ import print_function
from itertools import chain, combinations
data = [
['A', 'B', 'C'],
['A', 'C', 'E'],
['E', 'F', 'D'],
['D', 'A', 'J'],
['E', 'D', 'J'],
]
pairs = map(sorted, chain(*[combinations(row, 2) for row in data]))
module Kernel
SKIP_2357 = [2, 4, 2, 4, 6, 2, 6, 4, 2, 4, 6, 6, 2, 6, 4, 2, 6, 4, 6, 8, 4,
2, 4, 2, 4, 8, 6, 4, 6, 2, 4, 6, 2, 6, 6, 4, 2, 4, 6, 2, 6, 4,
2, 4, 2, 10, 2, 10]
def iterate(start, &f)
Enumerator.new do |y|
loop do
y << start
start = f.call start
class Palindromes
attr_reader :largest, :smallest
PalindromicProduct = Struct.new(:value, :factors) do
def to_str
"#{value} -> #{factors}"
end
end
def initialize(opts)
(ns sieve-comp)
(defmacro measure
[& body]
`(do
(System/gc)
(let [start# (System/nanoTime)
result# (do ~@body)]
[result# (- (System/nanoTime) start#)])))
@monzee
monzee / Makefile
Created April 17, 2016 04:06
A really simple makefile for single-file java programs. Put this in the same directory as the java file and run the program using `:!make main=%` in vim
path := $(dir $(main))
prefix := $(basename $(main))
class_name := $(notdir $(prefix))
COMPILE := javac
EXEC := java -cp .:$(path):$(cp)
.PHONY: run
run: $(prefix).class
$(EXEC) $(class_name)
public interface Contact {
class Person {
public final String name;
public final int phone;
public Person(String name, int phone) {
this.name = name;
this.phone = phone;
}
}
@monzee
monzee / Monads.java
Last active February 15, 2017 01:17
Monad interfaces for IO<T>, Option<T>, Either<L, R> and combined IO<Option<T>> (Job<T>) and IO<Either<L, R>> (Task<L,R>)
package m;
import java.util.function.*;
public class Monads {
static <T, U> Function<Option<T>, Option<U>>
lift(Function<T, U> t2u) {
return ot -> pu -> ot.map(t2u).match(pu);
}