Skip to content

Instantly share code, notes, and snippets.

View mewdriller's full-sized avatar

Drew Miller mewdriller

View GitHub Profile
@mewdriller
mewdriller / plur.js
Created November 8, 2019 16:24
plur.js
const getItemAt = (list, index) =>
list[Math.min(list.length - 1, Math.max(0, index))];
const plur = (...counts) => (strings, ...values) => {
let i = 0;
return strings
.reduce((result, string, index) => {
const value = values[index];
@mewdriller
mewdriller / settings.json
Created February 21, 2019 15:48
VS Code Settings
{
// General Settings:
"editor.fontLigatures": true,
"editor.fontFamily": "Fira Code",
"editor.fontSize": 13,
"editor.formatOnSave": true,
"editor.minimap.enabled": false,
"editor.rulers": [
// 54,
80,
@mewdriller
mewdriller / childDirective.js
Created September 1, 2015 22:03
bindToController, controllerAs, postLink w/ vm access
function childDirective() {
'ngInject';
function postLink(scope, element, attribute, [vm, ParentController]) {
// Initialization:
ParentController.register(vm);
// Handlers:
_.chain($('tbody tr'))
.map(function (row) {
return [
$(row).find('td:nth-child(1)').text().trim(),
$(row).find('td:nth-child(3)').text().trim()
];
})
.reject(function (pair) {
return pair[1] === 'absent';
})
@mewdriller
mewdriller / scoped-transclude.directive.js
Created March 31, 2015 19:36
An AngularJS directive to transclude while using the contextual scope.
'use strict';
module.exports = /*@ngInject*/ function scopedTransclude() {
return {
link: function postLink(scope, iElement, iAttributes, controller, transclude) {
if (!transclude) {
throw minErr('ngTransclude')('orphan',
'Illegal use of ngTransclude directive in the template! ' +
'No parent directive that requires a transclusion found. ' +
{
"nodeType": "Main",
"value": {
"nodeType": "Select",
"columns": [
{
"nodeType": "Column",
"value": {
"nodeType": "AndCondition",
"value": [

Keybase proof

I hereby claim:

  • I am mewdriller on github.
  • I am mewdriller (https://keybase.io/mewdriller) on keybase.
  • I have a public key whose fingerprint is A50D 6708 4888 0025 EEB3 DFE0 3358 2914 9177 ED70

To claim this, I am signing this object:

# app/controllers/api/v1/brands_controller.rb
module Api
module V1
class BrandsController < ApiController
def search
@results = SimilarBrandsQuery.new.similar_to(params.require(:q)).limit(10)
render json: @results, status: 200
end
end
@mewdriller
mewdriller / ability.rb
Last active December 19, 2021 01:48
Serializing CanCan rules to JSON for use in a client-side application
class Ability
include CanCan::Ability
def initialize(user)
can :read, Comment
if user.valid?
can :create, Comment
can :manage, Comment, author_id: user.id
end
<form id="edit-task-3">
<div class="properties">
<!-- Owner -->
<label>Owner</label>
<select class="input-block-level" data-provide="chosen">
<option value="s240946" selected="selected">Andrew Miller</option>
<option value="s244005">Anthony Borres</option>
</select>
<!-- Managers -->