Skip to content

Instantly share code, notes, and snippets.

@alixaxel
alixaxel / y.php
Last active October 13, 2016 12:41
Why...
<?php
namespace alixaxel;
class y
{
public static function Coalesce()
{
foreach (func_get_args() as $argument) {
if (isset($argument) === true) {
# coding=UTF-8
from __future__ import division
import re
# This is a naive text summarization algorithm
# Created by Shlomi Babluki
# April, 2013
class SummaryTool(object):
@aparrish
aparrish / portnameteau.py
Created April 18, 2013 22:31
simple algorithm for mashing together two english words
import re
import random
def vtoc_idx(s):
match_obj = re.search(r'[aeiou][^aeiou]', s.lower())
if match_obj:
return match_obj.start() + 1
else:
return None
<?php
function pre_print_r($var){
echo "<pre>";
print_r($var);
echo "</pre>";
}
function Bigrams($word){
@MarcelloDuarte
MarcelloDuarte / decrease_and_print.php
Created April 9, 2013 07:13
Even wondered how to use recursion in PHP closures?
<?php
$decrease = function($self, $number) {
if ($number >= 0) {
echo $number . PHP_EOL;
$self($self, --$number);
}
};
$decrease($decrease, 10);
@adriengibrat
adriengibrat / l.php
Last active January 22, 2024 14:45
Extreme minification of shortest possible PSR-0 compliant autoloader, 5 lines !
<?php
//set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__); // optional
spl_autoload_register(function ($class) {
$file = preg_replace('#\\\|_(?!.+\\\)#','/', $class) . '.php';
if (stream_resolve_include_path($file))
require $file;
});
<?php
function RESTful($root, $convention = '_%s')
{
$root = rtrim(str_replace('\\', '/', realpath($root)), '/');
$segments = preg_replace('~/+~', '/', trim(substr($_SERVER['PHP_SELF'], strlen($_SERVER['SCRIPT_NAME'])), '/'));
foreach (range(0, count($segments = explode('/', $segments))) as $i)
{
if (is_file(sprintf('%s/%s.php', $root, $path = implode('/', array_slice($segments, 0, $i)))) === true)
@gnarmis
gnarmis / minmaxheap.py
Created January 27, 2013 10:01
min max heap implementation in python
from math import log, floor, pow
class MinMaxHeap(object):
"""an implementation of min-max heap using an array,
which starts at 1 (ignores 0th element)
"""
def __init__(self, array=[]):
super(MinMaxHeap, self).__init__()
@leemartin
leemartin / slots.coffee
Last active June 23, 2020 13:05
CSS3 Slot Machine
$ ->
result = []
count = 0
# Loop through each reel
$('.reel-outer'). each ->
$this = $(this)
index = $this.index()
spinPlus = 0