Emoji |
---|
👍 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Extra Trello Edit Keys | |
// @namespace http://www.paperlesspost.com/ | |
// @version 0.1.1 | |
// @description From the card edit window, hit H to edit the description and Y to add a new comment. | |
// @match https://trello.com/* | |
// @copyright 2012+, Alan MacDougall | |
// ==/UserScript== | |
function main() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// replacing a function with a one-time suppression using _.wrap | |
var module = { | |
execute: function(target) { | |
doSomeBigAction(target); | |
} | |
}; | |
// it might be more clear if I assign this intermediate variable | |
var skipOnce = _(module.execute).wrap(function(original) { | |
console.log("Sorry, doing nothing this time."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 Cavern of Souls | |
2 Clifftop Retreat | |
4 Forest | |
2 Gavony Township | |
1 Kessig Wolf Run | |
1 Mountain | |
3 Plains | |
2 Rootbound Crag | |
4 Temple Garden |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// traditional for loop explains HOW to do everything; can you spot the | |
// interesting logic? | |
var textAssets = []; | |
for (var i = 0; i < this.assets.length; i++) { | |
if (this.assets[i].type == "text") { // <- the ONLY interesting logic is right here | |
textAssets.push(this.assets[i]); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PP.component = (function() { | |
var currentValue = null; | |
var previousValues = []; | |
/** | |
* Changes input values, maintaining a record of how often it has done so. | |
* This is a standard doc comment, and this is how it is phrased; when in | |
* doubt, write JavaDoc style. | |
*/ | |
var component = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Rejects items which match the iterator, beyond the threshold. Accepts all other items. | |
* | |
* Example: _([1, 1, 1, 1, 2]).limitQuantity(2, function(n) {return n == 1;}); // [1, 1, 2] | |
* | |
* @param list The list to be filtered. Omitted in OO-style (i.e. _(list).limitQuantity). | |
* @param n The number of matching items to be allowed. | |
* @param f The filter function against which list items will be matched. | |
*/ | |
_.limitQuantity || _.mixin({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Given a seq of channels, waits until each channel has received a value, and | |
;; then returns a vec of each value. | |
(defn barrier [cs] | |
(go (loop [cs (seq cs) result []] | |
(if cs | |
(recur (next cs) (conj result (<! (first cs)))) | |
result)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Without channels: | |
;; Makes an HTTP request, and executes the callback on the response when it | |
;; comes. This should be familiar from Javascript. | |
(defn get-pudding [callback] | |
(http-get {:url "pudding" | |
:success callback})) | |
(get-pudding (fn [response] (eat response))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This works, but since it has to take `n, f1, ...` instead of `n, [f1, ...]`, | |
// we need to do a messy concat/apply at the end. | |
function pipeline(n) { | |
var actions = rest(arguments); | |
if (_.isEmpty(actions)) { | |
return n; | |
} else { | |
return pipeline.apply(null, [first(actions)(n)].concat(rest(actions))); | |
} | |
}; |