Skip to content

Instantly share code, notes, and snippets.

Avatar

Lachlan Priest lcpriest

View GitHub Profile
View git-auto-rebase
# 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 / missing_tests.rake
Created May 16, 2018
Generate missing test files in a rails app
View missing_tests.rake
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 / dynamic-query-params.md
Last active Nov 1, 2018
EmberJS dynamic query params
View dynamic-query-params.md

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 / gist:c6448bb81d2193ffaafa64f8f5779b87
Last active Jul 24, 2017
Keyboard shortcuts for sublime
View gist:c6448bb81d2193ffaafa64f8f5779b87

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 Mar 22, 2017
Elasticsearch mapping with dynamic templates for customer attributes
View template.json
{
"template": "account-*",
"settings": {
"analysis": {
"analyzer": {
"default": {
"tokenizer": "keyword",
"filter": "lowercase"
}
}
View elasticsearch.rb
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 Jun 2, 2016
Common questions in Ruby + Ember
View gist:4f329d51fafbbfc167dd

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@lcpriest
lcpriest / index.js.erb
Created Oct 15, 2013
Simple implementation of autoscroll with will_paginate
View index.js.erb
$('#collection').append("<%= j render partial: 'partial', collection: @collection %>");
<% if @collection.next_page %>
$('.pagination').replaceWith('<%= j will_paginate(@collection) %>');
<% else %>
$('.pagination').remove();
<% end %>
You can’t perform that action at this time.