Skip to content

Instantly share code, notes, and snippets.

View patrixr's full-sized avatar
🌱
Slow growth

Patrick R patrixr

🌱
Slow growth
View GitHub Profile
@patrixr
patrixr / promisify.js
Created February 5, 2016 03:15
Promisify: from callback to promise
function promisify(func, scope) {
return function () {
var args = [].slice.call(arguments);
var deferred = Promise.defer();
args.push(function () {
if (arguments[0]) {
// There was an error
deferred.reject(arguments[0]);
@patrixr
patrixr / ci-ember-test.js
Created November 30, 2018 04:30
Minimal EmberJS testing output for CI
const chalk = require('chalk');
const cli = require('ember-cli');
const fs = require('fs');
let enableLog = false;
let failures = 0;
function wrapStream(stream) {
const _write = stream.write.bind(stream);
const _print = (txt) => _write(txt + "\n");
@patrixr
patrixr / ember-check-associations.js
Created May 17, 2019 07:19
Ember: Finding loaded associations
function hasMissingAssociations(record, associationName) {
if (_.isArray(associationName)) {
return _.some(associationName, name => {
hasMissingAssociations(record, name);
});
}
const relationship = record.relationshipFor(associationName);
if (!relationship) {
return false;
@patrixr
patrixr / deploy.yml
Created July 17, 2019 08:21
Hasura deployment
---
- hosts: all
remote_user: {{ REMOTE_USER }}
become: true
tasks:
- name: Install Docker
yum:
name: docker
state: present
@patrixr
patrixr / redux-mutations.js
Last active August 17, 2019 03:47
Experimental Redux Mutation Wrapper
import _ from 'lodash';
const ALLOWED_MUTATIONS = {
set(key) {
return (state, action) => ({ [key]: action[key] })
},
increment(key) {
return state => ({ [key]: state[key] + 1 });
},
@patrixr
patrixr / redux-mutations2.js
Created August 17, 2019 03:47
Redux Mutation Experiment 2
import _ from 'lodash';
export function setProperty(key) {
return (state, action) => ({ [key]: action[key] })
}
export function increment(key) {
return state => ({ [key]: state[key] + 1 });
}
@patrixr
patrixr / Palapa.rb
Last active February 27, 2021 06:38
page :home do
header do
add_link 'Home', to: :home
add_link 'Posts', to: :posts
end
section :description, layout: :horizontal do
section :image do
add_image '/some/image'
const RSVP = require('rsvp');
const Ember = { RSVP };
/**
* Returns a promise and a trigger to start the job
*
* @export
* @param {Function} func the job to execute
* @param {any} scope the scope to bind the function to
#
# MIGRATION
#
create_table :user_favourites do |t|
t.string :favourite_type, index: true
t.integer :favourite_id
t.integer :user_id
t.boolean :persitent, default: false # Setting this prop to true would essentially make it behave as a "favourite"