Skip to content

Instantly share code, notes, and snippets.

View rimian's full-sized avatar

Rimian Perkins rimian

View GitHub Profile
@rimian
rimian / pre-commit
Last active October 27, 2022 23:37 — forked from edisonywh/pre-commit
Run Rubocop in Git's pre-commit hook
```
#!/bin/sh
echo "\nRunning Rubocop 🚓 💨 💨 💨\n"
declare -a ERRORS=()
for file in $(git diff --cached --name-only | grep -E '.rb')
do
ERRORS+=("$(rubocop $file | grep -e 'C:' -e 'E:')")
done
@rimian
rimian / factoryspec.rb
Last active March 16, 2022 02:19
best way to test a factory method
class Pipeline
def self.run
new.run
end
def run
# do stuff
end
end
@rimian
rimian / gpg-setup.sh
Last active March 1, 2022 23:09
Get set up with Signed Commits on macOS
#!/bin/bash
INFO='\033[1;32m'
NC='\033[0m'
GNUPG_DIR="$HOME/.gnupg"
function info() {
echo -e "${INFO}$1${NC}"
}
@rimian
rimian / wizard.html
Last active May 6, 2021 01:13
Dashkit Wizard
<form class="tab-content">
<div class="tab-pane fade show active" id="wizardStepOne" role="tabpanel" aria-labelledby="wizardTabOne">
Step 1
<div class="row align-items-center mt-4">
<div class="col-auto">
<button class="btn btn-lg btn-white" type="reset">Cancel</button>
</div>
<div class="col text-center">
module Merge
class Base
attr_accessor :base, :compare
def initialize(base, compare)
@base = base
@compare = compare
end
end
already_booked = [
Event.new('2018-12-19 16:00:00', '2018-12-19 17:00:00'),
Event.new('2018-12-20 9:00:00', '2018-12-20 10:00:00')
]
available = [
Event.new('2018-12-19 16:00:00', '2018-12-19 17:00:00'),
Event.new('2018-12-20 9:30:00', '2018-12-20 11:30:00'),
Event.new('2018-12-21 9:00:00', '2018-12-20 11:00:00')
]
s.events = s.events.map { |e| e.end_date = e.end_date + 1.second }
stubPromise = () => new Em.RSVP.Promise(() => {});
promise_1 = Em.RSVP.defer({ promise: stubPromise() });
promise_2 = Em.RSVP.defer({ promise: stubPromise() });
promise_1.promise.then(() => console.warn(1, moment().valueOf()));
promise_2.promise.then(() => console.warn(2, moment().valueOf()));
moment().valueOf(); promise_1.resolve(); promise_2.resolve();
@rimian
rimian / eric-clapton.js
Created February 5, 2019 02:32
Promises
done = (msg, delay) => {
console.warn(msg, delay);
return msg;
};
p = (msg, delay) => new Em.RSVP.Promise((resolve) => Em.run.later(() => resolve(done(msg, delay)), delay) );
fast = [p('fast one', 3223), p('fast two',3509)];
slow = [p('slow one', 15523), p('slow two', 15509)];
const sum = (arr) => arr.reduce((a, b) => a + b);
const average = (arr) => sum(arr)/arr.length;
kms = $(".feature-title:contains('Odometer')").next('div').text().split(' km').filter(k => k.length).map(k => parseInt(k.replace(',', '')));
prices = $('.ad-price .price').text().split('$').filter(p => p.length).map(p => parseInt(p.replace(',', '')));
avKms = average(kms);
avPrice = average(prices);
pricePerKm = avPrice/avKms;