Skip to content

Instantly share code, notes, and snippets.

@tarot
tarot / map_values.coffee
Last active August 29, 2015 14:12
map values for underscore.js
_.mixin
map_values: (obj, iteratee, context) ->
iteratee = @iteratee iteratee, context
@object @map obj, (v, k, o) -> [k, iteratee(v, k, o)]
# Search shell history with peco: https://github.com/peco/peco
# Adapted from: https://github.com/mooz/percol#zsh-history-search
if which peco &> /dev/null; then
function peco_select_history() {
local tac=$( \
(which gtac &> /dev/null && echo -n "gtac") || \
(which tac &> /dev/null && echo -n "tac") || \
echo -n "tail -r" \
)
BUFFER=$(fc -l -n 1 | eval $tac | \
# https://github.com/heroku/rack-timeout/issues/76
class TimeoutRecovery
def initialize(app, options = {})
@app, @options = app, options
end
# Rack::Timeout, as of 0.2.4, raises errors that descend from the Exception
# class when a request takes too long - however, this is a very strong
# exception level and will kill Puma's worker if we let it continue down the
@tarot
tarot / heroku_up.sh
Last active August 29, 2015 14:22
web dynoをスケールするコマンド。事前にheroku config:setでHEROKU_API_KEYとHEROKU_APP_NAMEを設定する。
curl -n -X PATCH https://api.heroku.com/apps/${HEROKU_APP_NAME}/formation/web \
-H "Accept: application/vnd.heroku+json; version=3" \
-H "Authorization: Bearer ${HEROKU_API_KEY}" \
-H "Content-Type: application/json" \
-d '{"quantity":1}'
@tarot
tarot / package.json
Created June 19, 2015 11:26
ProfileのfieldPremissionとobjectPermissionを全部trueにする
{
"dependencies": {
"bluebird": "^2.9.9",
"commander": "^2.7.1",
"dotenv": "^0.5.1",
"glob": "^5.0.3",
"jsforce": "^1.4.0",
"jszip": "^2.5.0",
"lodash": "^3.5.0",
"shelljs": "^0.4.0",
$ ->
$('input[type="file"]').on 'change', (event) ->
reader = new FileReader()
reader.onload = ->
boundary = "ljfdshflashdlfkjaklsdfjlksadjflksajdflksajdklfas"
blob = new Blob [
[
"--#{boundary}"
'Content-Disposition: form-data; name="json"'
'Content-Type: application/json; charset=UTF-8'
@tarot
tarot / gulpfile.coffee
Created July 9, 2015 13:47
なんで"sourcesContent":[null]になるの?
gulp = require 'gulp'
sass = require 'gulp-sass'
sourcemaps = require 'gulp-sourcemaps'
gulp.task 'sass', ->
gulp.src './source/**/*.sass'
.pipe sourcemaps.init()
.pipe sass(indentedSyntax: true).on('error', sass.logError)
.pipe sourcemaps.write('.')
.pipe gulp.dest('./public')
@tarot
tarot / Strings.cls
Last active August 29, 2015 14:24
JavaScript style String::replace for Apex (Salesforce)
public class Strings {
public interface Replacer {
String apply(String match, String[] p, Integer offset, String str);
}
public static String replaceFirst(String str, String regExp, Replacer replacement) {
return replaceFirst(str, Pattern.compile(regExp), replacement);
}
@tarot
tarot / sample.page
Created July 30, 2015 06:57
何でこれがエラーになるの? "<apex:outputText> の値属性の形式が無効です。正数であり、データ型が数値、日付、時刻、または選択である必要があります。" ???
<apex:page standardController="Account">
<apex:outputField value="{!Account.CreatedDate}"/>
<apex:outputText value="{0,date}">
<apex:param value="{!Account.CreatedDate}"/>
</apex:outputText>
</apex:page>
@tarot
tarot / SampleExtension.cls
Created July 30, 2015 07:48
何故かこれは通る。{!Account.CreatedDate}と{!record.CreatedDate}が逆でもOK
public class SampleExtension {
public Account record { get; private set; }
public SampleExtension(ApexPages.StandardController controller) {
record = (Account) controller.getRecord();
}
}