Skip to content

Instantly share code, notes, and snippets.

View rpocklin's full-sized avatar

Robert Pocklington rpocklin

View GitHub Profile
@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 / docs.sh
Created October 17, 2014 13:25
Make rspec_api_documentation with apitome generate static HTML documentation (dirty but it works).
#!/bin/bash
wget -m http://localhost:3000/api/docs
mv localhost\:3000/ api-documentation
mv ./api-documentation/api/docs ./api-documentation/api/docs.html
@rpocklin
rpocklin / include-directive.js
Last active August 29, 2015 14:05
Angular directive which permits re-use for content referring to scope variables.
'use strict';
/**
* An ng-include replacement which transparently inherits the parent scope and also allows local customisation of variables
* within the snippet.
*
* Designed to use $templateCache (in production) and fallback to an AJAX request (for dev-mode) to load view templates.
*
* Use as below (can customise variables used in the snippet via ng-init):
* <div include="'users/_password_confirmation_input.html'" ng-init="placeholder = 'Re-enter Password'"></div>
@rpocklin
rpocklin / gist:09efefdb97c129c07d18
Created August 25, 2014 06:50
How to skip manually trusting new hosts for VMs
Set StrictHostKeyChecking no in your ~/.ssh/config file, where it will be the default for only the current user. Or you can use it on the command line:
ssh -o StrictHostKeyChecking=no -l $user $host
@rpocklin
rpocklin / ng-comments.html
Created July 1, 2014 01:31
AngularJS Comments which will be removed from production code
<div ng-if="false">
<!--
Here is a comment which will not be shown in production code.
-->
</div>
@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()));
},