Skip to content

Instantly share code, notes, and snippets.

View Tom-Alexander's full-sized avatar

Tom Alexander Tom-Alexander

View GitHub Profile
@Tom-Alexander
Tom-Alexander / parser.rb
Last active February 25, 2019 08:12
Recursive descent parser
# Recursive descent parser
# http://adayinthepit.com/2011/07/19/hanging-in-the-treetops/
def exp(stack)
token = stack.shift
return stack if token =~ /[0-9]/ || token =~ /X/ && exp(stack) || token =~ /Y|Z/ && exp(stack) && exp(stack)
false
end
def parse(source)
stack = exp(source.split(''))
@Tom-Alexander
Tom-Alexander / pathFromPolygon.js
Created April 28, 2016 19:57
Converts an SVG polygon to a path
function pathFromPolygon(points) {
var p = points.split(/\s+/);
var path = '';
for( var i = 0, len = p.length; i < len; i++ ) {
path += (i && 'L' || 'M') + p[i]
}
return path;
}
@Tom-Alexander
Tom-Alexander / suggested.php
Created February 17, 2016 00:58
silverstripe blog suggested posts
BlogPost::get()
->filter(['ParentID' => $this->owner->ParentID])
->leftJoin('BlogPost_Categories', 'BlogPost.ID = BlogPost_Categories.BlogPostID')
->where(
'BlogCategoryID IN (
SELECT BlogCategoryID FROM "BlogPost"
LEFT JOIN BlogPost_Categories ON BlogPost.ID = BlogPost_Categories.BlogPostID
WHERE BlogPost.ID = ' . $this->owner->ID . ')')
->exclude(['ID' => $this->owner->ID])
->sort('RAND()')
@Tom-Alexander
Tom-Alexander / EventEmitter.swift
Created December 12, 2015 10:37
swift pub-sub
import Foundation;
struct Consumer {
var name: String
var handler: (Any) -> Void
}
class EventEmitter {
static var consumers: [Consumer] = [];
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
proxy_connect_timeout 90;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_buffer_size 128k;
proxy_buffers 4 256k;
proxy_busy_buffers_size 256k;
proxy_intercept_errors on;
// Usage:
// .ReactCSSTransitionGroupMixin(
// {opacity: 0},
// {opacity: 1},
// {transition: opacity 300ms linear}
// );
.ReactCSSTransitionGroupMixin(@disabled, @active, @transition) {
&-enter {
@disabled();
&-active {
@Tom-Alexander
Tom-Alexander / silverstripe_3_2_upgrade.sh
Created November 17, 2015 20:12
Upgrade script for silverstripe 3.2
cd $1
if ! hash jq 2>/dev/null; then
brew install jq
fi
composer install
jq '.require."silverstripe/cms" = "~3.2.0"' composer.json > tmp.$$.json && mv tmp.$$.json composer.json
jq '.require."silverstripe/framework" = "~3.2.0"' composer.json > tmp.$$.json && mv tmp.$$.json composer.json
@Tom-Alexander
Tom-Alexander / README.md
Created November 12, 2015 21:22
Mailcatcher config
  1. gem install mailcatcher
  2. mailcatcher
  3. brew services restart php54
  4. nginx -s reload
  5. Go to http://mail.dev/
@Tom-Alexander
Tom-Alexander / magento.conf
Created November 11, 2015 22:31
nginx config for magneto
server {
listen 8080;
root /Users/user/Sites/magento.co.nz;
server_name magento.dev "~magento\.(.*)\.xip\.io$";
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
proxy_connect_timeout 90;
proxy_send_timeout 180;
proxy_read_timeout 180;
.sprite-animation(@name, @frame-width, @frame-height, @url, @frame-count, @sprite-width, @duration) {
width: @frame-width;
height: @frame-height;
display: block;
background: url(@url) left center;
animation: @name @duration steps(@frame-count) infinite;
@keyframes @name {
100% {
background-position: @sprite-width;
}