Skip to content

Instantly share code, notes, and snippets.

View rpocklin's full-sized avatar

Robert Pocklington rpocklin

View GitHub Profile
@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"
@rpocklin
rpocklin / puma_rufus_scheduler.rb
Last active March 3, 2017 13:35
How to set rufus scheduler affinity to first worker thread in puma
## in config/puma.rb
on_worker_boot do |worker_number|
# only create scheduler on first worker thread
if worker_number === 0
$scheduler_thread = true
end
end
@rpocklin
rpocklin / hb-includes.js
Last active December 27, 2015 12:58
Some HB handlers which extend template functions.
/* assume you have a HB template compiled called 'question_btn'
which contains {{outlet}} within it as optional embedded content
# example of question_btn.hbs
<a target="_blank" href="{{question_url}}">
<button type="button" class="pull-right btn question" title="ask seller a question">
{{#if outlet}}{{outlet}}{{else}}<i class="icon-question-sign"></i>{{/if}}
</button>
</a>
@rpocklin
rpocklin / jshint.xml
Last active December 26, 2015 22:49
My current Intellij JSHint file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JSHintConfiguration" version="2.1.0" use-config-file="false">
<option bitwise="true" />
<option camelcase="true" />
<option curly="true" />
<option eqeqeq="false" />
<option forin="true" />
<option immed="false" />
<option latedef="true" />
@rpocklin
rpocklin / vanilla_ember_on_rails.js
Last active December 26, 2015 07:19
Get emblem-rails working on any Rails 3.1+ app without ember.js handlebars.js is required
// add gem 'emblem-rails' to your Rails Gemfile and run 'bundle'
// create your template file in your Rails project
/app/assets/javascripts/templates/test.raw.emblem eg. 'h1 {{title}} world'
// add the following to your Rails application.js
Ember = {TEMPLATES: [], Handlebars: Handlebars}
//= require_tree ./templates
// anywhere later in your code - call it as a compiled template:
@rpocklin
rpocklin / responsive-mixin.sass
Last active December 23, 2015 21:09
SASS 3.2 Mixin for easy responsive declarations (break-points) Uses the best of SASS variables and @each to simply define break-points in a more natural language.
/* responsive break points - customise to suit or add more */
$break-small: 480px;
$break-medium: 768px;
$break-large: 940px;
$break-x-large: 1140px;
/* how to use:
@include devices(mobile) { - targets a single device
body {
@rpocklin
rpocklin / localStorage.js
Created September 6, 2013 06:32
Backbone model using localstorage as an auxiliary storage mechanism (giving you session-esque properties in the frontend). Uses Require.js, just strip if back if you don't use it. Recommendation is to call loadFromStorage() in initialize() method and call saveToStorage() when the model changes.
define(['backbone'],
function(Backbone) {
return Backbone.Model.extend({
_storage: localStorage || {setItem: function() {}, getItem: function() {return {};}},
saveToStorage: function() {
this._storage.setItem(this._getKey(), JSON.stringify(this.toJSON()));
},
@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 / 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();
});
});
if (!this.opts.allowClear) {
this.container.removeClass("select2-allowclear");
}