Skip to content

Instantly share code, notes, and snippets.

View lcpriest's full-sized avatar

Lachlan Priest lcpriest

  • Singapore, Singapore
View GitHub Profile
# git-auto-rebase
# git-auto-rebase --force-push
function git-auto-rebase() {
target="master"
if [[ $@ = "--force-push" ]]
then
push=true
else
push=false
@lcpriest
lcpriest / dynamic-query-params.md
Last active November 1, 2018 12:43
EmberJS dynamic query params

I was attempting to generate a list of links and found that some of them needed query params and others didn't. I could not find a recommended way to pass in a dynamic query-params object to the link-to helper. I ended up finding a solution in the Ember Discourse and decided to make it into an ember helper.

Helper:

import Ember from 'ember';

export function dynamicParams([routeName, params]/*, hash*/) {
 return [
@lcpriest
lcpriest / missing_tests.rake
Created May 16, 2018 02:35
Generate missing test files in a rails app
namespace :missing_tests do
def progress(name, x, y)
print "\r #{name}: #{x}/#{y} %6.2f%%" % [x.to_f / y * 100]
end
def generate_files(name)
kind = name.to_s.singularize
collection = Dir.glob Rails.root.join('app', name.to_s, '**', '*').to_s
root = Rails.root.join('app', name.to_s).to_s << '/'
ext = case name
@lcpriest
lcpriest / gist:c6448bb81d2193ffaafa64f8f5779b87
Last active July 24, 2017 18:08
Keyboard shortcuts for sublime

cmd + option + (1,2,3,4,5) for split sublime into panes

cmd + shift + p to open sublime command palette

cmd + c with nothing selected in sublime copies the entire line for pasting

cmd + x with nothing selected in sublime cuts the entire line for pasting

ctrl + cmd + (up,down) to move entire line up or down

@lcpriest
lcpriest / template.json
Created March 22, 2017 09:20
Elasticsearch mapping with dynamic templates for customer attributes
{
"template": "account-*",
"settings": {
"analysis": {
"analyzer": {
"default": {
"tokenizer": "keyword",
"filter": "lowercase"
}
}
client = ElasticWrapper::Session.new.client
client.search(index: 'test', type: 'contacts', body: body)
body = { query: { bool: { filter: { term: { name: 'lachlan' } } } } }
=>
[{
"_index"=>"test",
"_type"=>"contact",
"_id"=>"1",
@lcpriest
lcpriest / questions.md
Last active June 2, 2016 03:44
Common questions in Ruby + Ember
@lcpriest
lcpriest / index.js.erb
Created October 15, 2013 21:35
Simple implementation of autoscroll with will_paginate
$('#collection').append("<%= j render partial: 'partial', collection: @collection %>");
<% if @collection.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@collection) %>');
<% else %>
$('.pagination').remove();
<% end %>
@lcpriest
lcpriest / gist:4f329d51fafbbfc167dd
Created November 14, 2015 04:36 — forked from iangreenleaf/gist:b206d09c587e8fc6399e
Rails naming conventions

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.