Skip to content

Instantly share code, notes, and snippets.

View rpocklin's full-sized avatar

Robert Pocklington rpocklin

View GitHub Profile
@rpocklin
rpocklin / word.rb
Created August 22, 2011 23:19
simplifying code (from Java to groovy or ruby)
Ruby / Groovy
def get_types
words.collect{|word| word.word_type}
end
15 seconds to code.
3 seconds to read and understand.
Easy to read = self documenting.
Less LOC = better codebase and more agile team.
@rpocklin
rpocklin / memoize_class_example.rb
Created March 6, 2012 02:01
memoizing a class method in ruby
require 'active_support'
## strange this isn't done implicitly
class A
class << self
extend ActiveSupport::Memoizable
def my_class_method(x)
# cool stuff here
@rpocklin
rpocklin / confirm_process_not_running.sh.sh
Created September 7, 2012 06:10
Shows the number of processes running given a grep <string> and exit 1 if still running.
#!/bin/bash
let "RESULT=$(ps ax | grep $1 | wc -l) - 1" ;echo "$RESULT processes found for $1."; if [ "$RESULT" == 0 ]; then exit 0; else exit 1;fi;
@rpocklin
rpocklin / remove_svn_folders.sh
Created September 19, 2012 02:20
Removes horrible .svn directories from current path (and recurses) so that you can move them safely into folders as new files to be checked in
rm -rf `find . -type d -name .svn`
@rpocklin
rpocklin / gist:5156541
Created March 13, 2013 21:35
coerce a single or array parameter into array - keeping args flexible
def some_method(single_or_array)
single_or_array = [*single_or_array]
# do awesome stuff here...
end
$("#e2").select2({
placeholder: "Select a State",
allowClear: true
});
if (!this.opts.allowClear) {
this.container.removeClass("select2-allowclear");
}
@rpocklin
rpocklin / jquery_fade_promise_chaining.js
Created July 22, 2013 22:20
Getting fade in/out promises to work in JQuery without nested callbacks
var deferred = new $.Deferred();
result.fadeTo(2000, 0.4, function() {
deferred.resolve();
});
deferred.done(
function() {result.addClass('ending'); result.fadeTo(2000, 1.0, function() {
deferred = new $.Deferred().resolve();
});
});
@rpocklin
rpocklin / toggles.scala.html
Created July 26, 2013 07:51
Scala feature toggles
@(toggle: String)(enabledContent: Any)(disabledContent: Any)
@import play.api._
@defining(Play.current.configuration.getBoolean("toggles." + toggle)) { toggleValue =>
@toggleValue match {
case Some(toggleEnabled) => {
@if(toggleEnabled) {
@rpocklin
rpocklin / Build.scala
Last active March 11, 2017 08:59
Play 2.1 with Scala 2.10 and Jasmine sbt package, with auto-recompilation of LESS (including bootstrap), Jenkins build info, with coffeescript recompilation on (for sources and for specs in coffeescript). Sugar to taste.
import sbt._
import sbt.Keys._
import play.Project._
import sbtbuildinfo.Plugin._
import com.gu.SbtJasminePlugin._
object ApplicationBuild extends Build {
val appName = "your-app-name"
val appVersion = "1.0-SNAPSHOT"