Skip to content

Instantly share code, notes, and snippets.

View sperelson's full-sized avatar

Stephen Perelson sperelson

View GitHub Profile
@sperelson
sperelson / Pure CSS FizzBuzz.markdown
Last active August 29, 2015 14:21
Pure CSS FizzBuzz
@sperelson
sperelson / GoApp.sh
Created January 5, 2015 22:24
BBEdit 11 scripts to help build GoLang files and apps
#!/bin/bash
# Builds a Go app where the src folder is part of the default folder structure
# This assumes you have the app's src folder open in BBEdit and not any of the subfolders. Otherwise horrible dirname dirname won't work
# Setting the GOPATH may be a mistake?
# You may desire finer control over the output
# The src's folder name may not be desirable as your binary name
folder=$(basename "$BBEDIT_INSTAPROJECT_ROOT")
if [ "$folder" != "" ]; then
cd $(dirname `dirname "$BBEDIT_INSTAPROJECT_ROOT"`)
GOPATH=$(dirname `dirname "$BBEDIT_INSTAPROJECT_ROOT"`) go build -o $folder $folder
@sperelson
sperelson / ChristmasTreeBox.py
Last active August 29, 2015 13:57
A fun entry into the NML code challenge. The challenge's aims are: 1) with the fewest lines; and 2) in the most obscure, unreadable, unmaintainable manner possible. I've, however, decided to use Python in my personal aim of using a different language for each code challenge.
#!/usr/bin/python
import sys
if len(sys.argv) == 3:
width, height = [int(i.strip()) for i in sys.argv[1:]]
drawheight = height
while drawheight > 0:
if drawheight == height or drawheight == 1:
@sperelson
sperelson / prod.php
Created September 11, 2013 20:00
A Laravel 4.x snippet that will extend the cache driver with a new one that supports AWS ElastiCache. Blogged at http://blog.hapnic.com/2013/09/11/Laravel-4-and-ElastiCache/
<?php
// Register the special elasticache handler here
Cache::extend('elasticache', function() {
require_once(__DIR__.'/../libraries/ElasticacheConnector.php');
$servers = Config::get('cache.memcached');
$elasticache = new Illuminate\Cache\ElasticacheConnector();
$memcached = $elasticache->connect($servers);
@sperelson
sperelson / ElasticacheConnector.php
Created September 11, 2013 19:56
A custom Laravel 4.x cache connector for extending the default memcached driver to support AWS ElastiCache. It is missing the important part: the Cache::extend() instruction. I've blogged the whole thing at blog.hapnic.com/2013/09/11/Laravel-4-and-ElastiCache/
<?php namespace Illuminate\Cache;
use Memcached;
class ElasticacheConnector {
/**
* Create a new Memcached connection.
*
* @param array $servers
@sperelson
sperelson / ServeMixup.php
Created October 12, 2012 15:58
Mixup PHP curl routines with memcache
<?php
// Copyright Stephen Perelson
//
// Example PHP script to get a banner from http://mixup.hapnic.com
// Adds a 1 minute cache of the banner using Memcache
// Untested code
//
// Mixup is a cross-Promotion Linksharing service for Mxit web apps
class ServeMixup {