Skip to content

Instantly share code, notes, and snippets.

@smasty
smasty / filter.java
Last active August 29, 2015 14:01
Filter projects based on criteria. Uses a filterable Iterator with custom predicate, regexps and reflection.
/**
* List projects based on criteria.
* @param action
* @param user
*/
public Iterable<IProject> executeAction(ListProjectsAction action, IUser user) {
Iterable<IProject> items = projects.values();
if(action.getParams().containsKey("filter")){
Pattern pattern = Pattern.compile(Pattern.quote(action.getParam("pattern"))
@smasty
smasty / 99-bottles.foo
Created July 26, 2010 14:33
99 bottles made in Foo language.
&100(1 -1 $i " bottles of beer on the wall, " $i " bottles of beer." $c10 -1 "Take one down and pass it around, " $i " bottles of beer on the wall." +1 $c10$c10)
"No more bottles of beer on the wall, no more bottles of beer." $c10 "Go to the store and buy some more, 99 bottles of beer on the wall."$c10$c10
@smasty
smasty / .htaccess
Created April 9, 2011 15:05
WiPhiki - world's 3rd shortest wiki
RewriteEngine On
RewriteRule ^(.*)$ index.php?p=$1 [L,QSA]
@smasty
smasty / status-checker.php
Created June 27, 2011 19:29
Keyboard LED Gmail checker
#!/usr/bin/env php
<?php
/**
* Checks your GMail for unread messages and lets your keyboard LED diod blink if there are some.
*
* (c) Martin Srank (http://smasty.net)
* Licensed under the MIT License - http://opensource.org/licenses/mit-license
* Use at your own risk. Tested on Debian Squeeze.
*/
@smasty
smasty / bashrc.sh
Created September 14, 2011 14:29
Bash prompt with exit code and Git branch
# ========= PS1 SETTINGS
# Git branch
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/@\1/'
}
# Pipe code notifiation
bash_prompt_command() {
@smasty
smasty / SmartPresenterFactory.php
Created September 25, 2011 10:16
Smart presenter factory - supports custom name conventions for presenters.
<?php
namespace Smasty\Extensions;
use Nette,
Nette\Environment;
/**
* Smart presenter factory - supports custom name conventions for presenters.
@smasty
smasty / Navigation.breadcrumbs.latte.html
Created September 25, 2011 10:25
NavigationControl for Nette Framework
{*
* Available variables:
* - $control (NavigationControl) The control.
*}
<div class="control breadcrumbs" n:inner-foreach="$control->getComponents() as $node">
{if $iterator->last}
<span class="current">{$node->label}</span>
{else}
<a href="{$node->link}">{$node->label}</a> &raquo;
{/if}
@smasty
smasty / GameOfLife.php
Created May 20, 2012 13:01
The Game of Life in PHP
<?php
/**
* The Game of Life - a PHP simulator of the famous game.
* Early development state.
*
* Copyright 2011 Martin Srank (http://smasty.net)
*
* This source file is subject to the MIT license:
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
@smasty
smasty / gist:3800452
Created September 28, 2012 15:15
Converts unprintable PDFs exported to SVG by Evince to PNG images.
<?php
$data = file_get_contents($argv[1]);
$offset = isset($argv[2]) ? $argv[2] : 0;
if(preg_match_all('~data:image\/png;base64,([^"]+)"~i', $data, $matches)){
foreach($matches[1] as $k=>$i){
$id = $k+1+$offset;
echo "Processing page $id...";
$image = imagecreatefromstring(base64_decode($i));
@smasty
smasty / test.lua
Last active February 20, 2016 13:23
Test
-- manifest test
-- testing push access to gist repo