Skip to content

Instantly share code, notes, and snippets.

@IsTest
private class CalloutSampleTest {
public class CalloutMock implements HttpCalloutMock {
public HttpResponse respond(HttpRequest req) {
return new HttpResponse();
}
}
@IsTest
@tarot
tarot / DateFormat.cls
Last active February 19, 2020 16:09
Apexでhttp-date (RFC1123)
public class DateFormat {
private static final Map<String, Integer> MONTHS = new Map<String, Integer> {
'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4, 'May' => 5, 'Jun' => 6,
'Jul' => 7, 'Aug' => 8, 'Sep' => 9, 'Oct' => 10, 'Nov' => 11, 'Dec' => 12
};
public static Datetime fromRFC1123(String x) {
String[] dateParts = x.split('[\\s:]');
Integer year = Integer.valueOf(dateParts[3]);
@tarot
tarot / a.rb
Last active October 12, 2015 00:14
_typeがサブクラスを指すようにしたい。
class Picture < ActiveRecord::Base
belongs_to :imageable, polymorphic: true
end
class Product < ActiveRecord::Base
end
class PublicProduct < Product
has_one :picture, as: :imageable
end
@tarot
tarot / ABC.keylayout
Last active October 11, 2015 15:39
Option, Option+Shiftのレイアウトをブランクに設定したやつ。あと¥を\にしてる。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE keyboard PUBLIC "" "file://localhost/System/Library/DTDs/KeyboardLayout.dtd">
<!--Created by Ukelele version 2.2.8 on 2015-10-11 at 20:11 (JST)-->
<!--Last edited by Ukelele version 2.2.8 on 2015-10-12 at 00:37 (JST)-->
<keyboard group="0" id="11413" name="ABC (option keystrokes blank)" maxout="1">
<layouts>
<layout first="0" last="17" modifiers="f4" mapSet="16c"/>
<layout first="18" last="18" modifiers="f4" mapSet="984"/>
<layout first="21" last="23" modifiers="f4" mapSet="984"/>
<layout first="30" last="30" modifiers="f4" mapSet="984"/>
@tarot
tarot / normalize.rake
Created October 6, 2015 19:52
空配列と空ハッシュで改行しないJSON.pretty_generate モンキーパッチ版
require 'json'
require 'json/pure/generator'
module JSON::Pure::Generator::GeneratorMethods
%i(Fixnum Bignum).each do |constant|
const_set constant, Integer
end
module Array
alias_method :pure_to_json, :to_json
@tarot
tarot / normalize.rake
Last active October 6, 2015 19:44
空配列と空ハッシュで改行しないJSON.pretty_generate 先にjson/extがロードされてても大丈夫版
require 'json'
require 'json/pure/generator'
module Generator
module GeneratorMethods
(JSON::Pure::Generator::GeneratorMethods.constants - %i(Array Hash Integer)).each do |constant|
const_set constant, JSON::Pure::Generator::GeneratorMethods.const_get(constant)
end
%i(Fixnum Bignum).each do |constant|
@tarot
tarot / alert.js
Last active September 24, 2015 12:29
document.querySelector('#phHeaderLogoImage').src = 'http://pic.prepics-cdn.com/f2de00c74d43/17946611.jpeg'
@tarot
tarot / myfirstltng.cmp
Last active September 22, 2015 08:11
<aura:component implements="force:appHostable" controller="myfirstltngController">
<aura:attribute name="account" type="Account"/>
<aura:handler name="init" action="{!c.init}" value="{!this}"/>
{!v.account.Name}
<button onclick="{!c.save}">click</button>
</aura:component>
@tarot
tarot / reduce.js
Created August 17, 2015 04:18
you can't javascript under pressure #5
function(i) {
var fn = function(sum, e) {
if (typeof e === typeof 0) return sum + e;
if (e instanceof Array) return e.reduce(fn, sum);
return sum;
};
return i.reduce(fn, 0);
};
@tarot
tarot / Readme.md
Last active February 28, 2018 13:21
rails, postgres, redis, hipchat-notify, heroku-deployなwercker.yml

Werckerの設定

Environment variables

hipchat-notify用の設定。werckerのApplication Settings (右上の歯車アイコン) → Environment variables から、HIPCHAT_TOKENHIPCHAT_ROOM_IDを追加する。