Skip to content

Instantly share code, notes, and snippets.

View IgnusG's full-sized avatar
:octocat:
That’s weird, where did the status go?

JJ IgnusG

:octocat:
That’s weird, where did the status go?
View GitHub Profile
function isMultipleOf(x, say) {
return (i) => i % x == 0 ? say() : '';
}
const thenSay = (say) => () => say;
// The order matters. Any function with the signature (any)->(int)->str is valid
const whatShouldISayWhen = [
isMultipleOf(3, thenSay('Fizz')),
isMultipleOf(5, thenSay('Buzz'))
];

Closing & Opening

Action Keyboard Shortcut
Close Ctrl + F4
Close Others Alt + Shift + F4
Close All Ctrl + Alt + Shift + F4
Close Unmodified Alt + F4
Reopen Ctrl + Shift + T
@IgnusG
IgnusG / context-loader.js
Last active September 6, 2016 19:20
Modifies context of imports. Should be called before whatever compiles the imports
const fs = require('fs');
const requirePatterns = [
/(import.*from\W*)(?:(')(.*)(?!\/)'|(")(.*)(?!\/)")(.*)/g,
/(require\W*\()(?:(')(.*)(?!\/)'|(")(.*)(?!\/)")(.*)/g
];
const extension = '.ts';
function decodeOption(key, value) {
switch (key) {
@IgnusG
IgnusG / map_through_associations.rb
Last active August 25, 2016 16:05
Will map through all associations defined on a rails model and collect the result of a shared method
klas = item_type.constantize
has_many_associations = klas.reflections.collect { |_, c| c.class_name if c.macro == :has_many }.compact
has_one_associations = klas.reflections.collect { |_, c| c.class_name if c.macro == :has_one }.compact
instance = klas.find item_id
@result = instance.some_method
has_one_associations.each do |assoc_string|
assoc_string = assoc_string.underscore