Skip to content

Instantly share code, notes, and snippets.

View kapowaz's full-sized avatar

Ben Darlow kapowaz

View GitHub Profile
@kapowaz
kapowaz / gist:81c9e3153f799e6e13c6
Created May 28, 2014 14:14
This monstrosity comes from Spree's address form view.
<% if Spree::Config[:address_requires_state] %>
<p class="field" id=<%="#{address_id}state" %>>
<% have_states = !address.country.states.empty? %>
<%= form.label :state, Spree.t(:state) %><span class='required' id=<%="#{address_id}state-required"%>>*</span><br/>
<% state_elements = [
form.collection_select(:state_id, address.country.states,
:id, :name,
{:include_blank => true},
{:class => have_states ? 'required' : 'hidden',
@kapowaz
kapowaz / Gemfile
Created October 15, 2013 15:00
A simple gemfile for Rails 3.2
source "http://rubygems.org"
ruby "2.0.0"
gem "rails", "~> 3.2"
def self.process_randoms(text)
stack = []
stored_string = ""
random_choices = []
scanner = StringScanner.new(text)
while match = scanner.scan_until(/[\{\}\|]|\[(one of|or|at random)\]/)
stored_string << match.slice(0, match.length - scanner.matched_size)
case scanner.matched
when "{", "[one of]"
@kapowaz
kapowaz / jquery.transitionevents.js
Created August 15, 2013 10:34
A simple convenience method to bind single-use callbacks to the end of transition effects, making chaining transitions a little less callback-hellish.
// convenience method for applying a transition class, with a callback
// usage:
// $('div.foo').transition('zoomed', function(){ console.log('your div is now zoomed!'); });
// $('div.bar.faded').transition('!faded', function(){ console.log('your div is no longer faded'); });
jQuery.fn.transition = function(className, callback) {
var element = $(this),
transitionEndEvents = 'webkitTransitionEnd mozTransitionEnd msTransitionEnd oTransitionEnd transitionEnd transitionend',
transitionCallback = function transitionCallback(){
element.unbind(transitionEndEvents);

Advantage Goal

The Problem

In high-profile knock-out tournament matches, teams tend to play defensively if the game remains drawn towards the end. As extra time and penalties loom, teams sometimes play /for/ penalties, knowing that whilst they may not be able to score from free play, they /might/ win the penalty shoot-out. This tends to make the game less entertaining for spectators, and can result in a result which some may deem didn't fairly reflect the balance of play. FIFA have stated they would like to see penalty shoot-outs ended, but previous solutions (the ‘golden’ and ‘silver’ goals) have proven unpopular, and have since been largely dropped.

Proposal

@kapowaz
kapowaz / next_power_two.rb
Created May 13, 2012 13:00
Determine the next power of two above a given number
def next_power_two(number)
number.to_s(2).split("").inject("") {|s, c| s+= "1" }.to_i(2) + 1
end
@kapowaz
kapowaz / gist:1985666
Created March 6, 2012 10:52
An idea for an alternative syntax for scoped styles
<html>
<head>
<style>
@scope 'body > div:nth-child(2)' {
div { color: red; }
span { color: green; }
}
</style>
</head>
<body>
@kapowaz
kapowaz / template_helpers.rb
Created January 19, 2012 17:14
Register .html as a template type within a Sinatra app by aliasing ERB
class MyApp < Sinatra::Base
Tilt.register Tilt::ERBTemplate, :html
module TemplateHelpers
def html(*args)
render :html, *args
end
end
helpers TemplateHelpers
@kapowaz
kapowaz / admin.html
Created March 2, 2011 14:37
An example of what you can do with CSS 3 in webkit browsers
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Admin Home</title>
<style type="text/css">
html, body { height:100%; margin:0; padding:0; }
body
{
<html><head><title></title></head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
function AddField(){
var d_name = $("#d_name").val();
var d_number = $("#d_number").val();
var field = $("#field").val();