Skip to content

Instantly share code, notes, and snippets.

View tochi's full-sized avatar

tochi tochi

View GitHub Profile
+ (BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)url {
NSError *error = nil;
BOOL success = [url setResourceValue: [NSNumber numberWithBool: YES] forKey: NSURLIsExcludedFromBackupKey
error: &error];
if(!success){
// Error
}
return success;
}
apple_url = “https://buy.itunes.apple.com/verifyReceipt”
receipt_data = params[“receipt-data”]
res = RestClient.post apple_url, {:’receipt-data’ => receipt_data}.to_json
res = JSON.parse(res)
if res[“status”] == 21007
apple_url = “https://sandbox.itunes.apple.com/verifyReceipt”
receipt_data = params[“receipt-data”] res = RestClient.post apple_url, {:’receipt-data’ => receipt_data}.to_json
res = JSON.parse(res)
end
ON CONFLICT (id) DO UPDATE SET "title"=EXCLUDED."title","updated_at"=EXCLUDED."updated_at" RETURNING "id"
INSERT INTO "posts" ("id","title","description","created_at","updated_at")
VALUES
(1,'1つめの記事です','2018-08-22 01:14:24.649575','2018-09-01 00:45:18.474184'),
(2,'2つめの記事です','2018-08-22 01:14:24.649575','2018-09-01 00:45:18.474184')
ON CONFLICT (id) DO UPDATE SET "title"=EXCLUDED."title","updated_at"=EXCLUDED."updated_at" RETURNING "id"
posts = post_ids.map.with_index(1) do |post_id, i|
post = Post.find(post_id)
post.title = "#{i}つめの記事です"
post
end
self.import(posts, on_duplicate_key_update: { conflict_target: %i(id), columns: %i(title)) })
- (NSDictionary *)verifyReceipt:(NSString *)base64Receipt isCoercion:(BOOL)isCoercion isSandbox:(BOOL)isSandbox {
if (_completed || isCoercion) {
if (base64Receipt) {
NSURL *url = [NSURL URLWithString:isSandbox ? @"https://sandbox.itunes.apple.com/verifyReceipt" : @"https://buy.itunes.apple.com/verifyReceipt"];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
NSDictionary *requestContents = @{
@"receipt-data": base64Receipt,
@"password": SHARED_SECRET
};
...
@tochi
tochi / index.html.haml
Created April 2, 2019 13:19
Point of Sale for Square
%h1 Squareとの連携
= text_field_tag :price, 100
= button_tag '送信'
:javascript
const button = document.getElementsByName('button')[0]
button.addEventListener('click', () => {
const price = document.getElementsByName('price')[0]
const dataParameter = {
@tochi
tochi / devise_invitable.ja.yml
Last active June 21, 2016 13:12
Japanese locale file for DeviseInvitable
ja:
devise:
failure:
invited: 'アカウントを作成するには、保留中の招待を承認してください。'
invitations:
send_instructions: '招待メールが%{email}に送信されました。'
invitation_token_invalid: '招待コードが不正です。'
updated: 'パスワードが設定されました。お使いのアカウントでログインできます。'
updated_not_active: 'パスワードが設定されました。'
no_invitations_remaining: 'これ以上招待できません。'
@tochi
tochi / gist:7798779
Last active December 30, 2015 07:49
k="乾杯",b="大きな",y="君",n="今",d="日",h="たい",r="ろう"
['作詞:','作曲:'].map{|w|w+"長渕剛"}
"か#{h}絆に思いをよせて語り尽くせぬ青春の#{d}々#{['傷つき','喜び'].map{|w|a(w)}}肩をたたきあったあの#{d}あれからどれくら#{h.reverse}ったのだ#{r}沈む夕陽をいくつ数えた#{r}故郷の友は#{n}でも#{y}の心の中にいますか"
m(k,y,b)
"キャンドルライトの中の二人を#{n}こうして目を細めてる#{b}喜びと少しのさみしさを涙の言葉で歌い#{h}明#{d}の光を身体にあびてふり返らずにそのまま行けばよい#{['風に吹か','雨に打た'].map{|w| b(w)}}信じた愛に背を向けるな"
2.each(i){m(k,y,b)}
m(k,y,b){"#{k}!今#{y}は人生の#{b*2}舞台に立ち遥か長い道のりを歩き始めた#{y}に幸せあれ!"}
a(k){"時には#{k}"}
b(k){"#{k}れても"}
@tochi
tochi / Configuration.h
Created August 9, 2012 02:21
NSUserDefaultsを使うときはWrapして使うと便利 ref: http://qiita.com/items/2af840ded249b3e4e9bb
@interface Configuration : NSObject
+ (NSString *)name;
+ (void)setName:(NSString *)value;
+ (BOOL)setting;
+ (void)setSetting:(BOOL)value;
+ (void)synchronize;
@end