Skip to content

Instantly share code, notes, and snippets.

View ainame's full-sized avatar

Satoshi Namai ainame

View GitHub Profile
require 'yaml'
cops = File.read('.rubocop_todo.yml')
.split("\n\n")
.drop(1)
.map {
{
count: _1.match(/Offense count: (\d+)/).captures[0].to_i,
yaml: YAML.load(_1),
auto_correct: _1.match(/Cop supports --auto-correct/) != nil
}
@ainame
ainame / Mappable.swift
Created November 7, 2019 01:23
NSManagedObjectから任意のモデルに相互にマップしあう定義をプロトコル化するとCoreData Wrapper書くのに捗りそう
import Foundation
import CoreData
protocol NSManagedObjectMappable: NSManagedObject where MapFrom.MapFrom == Self {
associatedtype MapFrom: MappableFromNSManagedObject
static func mappedObject(from object: MapFrom, in context: NSManagedObjectContext) -> Self
}
enum MappingError: Error {
case missingNonOptionalValue(String)
@ainame
ainame / shibuya-el-position-paper.md
Created August 18, 2012 06:19
shibuya.elのポジションペーパーです。githubアカウントをお持ちの方はforkしてお使いください。

Shibuya.el#1 ポジションペーパー

Personal

  • 名前(任意)

    • xxxxxx xxxxxxx
  • Twitter or Facebookのアカウント or HN等

  • @xxxxxx

@ainame
ainame / matome.md
Last active October 4, 2017 08:16
井戸端iOS飯で過去に見た動画まとめ

井戸端iOS飯

とは?

井戸端iOS飯とは、昼休み1時間+MTG分の30分の計1時間30分を利用して、 NBFオフィスのコラボのプロジェクターとスクリーンを利用して、 最新のスマホアプリ開発技術に関する動画を見ながらご飯を食べて、 交流する場です。

ぜひお気軽にご参加ください。

@ainame
ainame / gist:a4f8dc30400f0dc05c96
Created April 30, 2013 11:52
チートシート

extreme fish bowl

問題

extreme fish bowlルール説明

  1. 2人1組になってプログラムを書く
  2. 書く人(ドライバー)と、横で考える人(ナビゲーター)は随時入れ替える
  3. コーディングするときは必ず何を書こうとしているのか喋りながら書く
  4. 15分の作業が終わる前にgit commitして、速やかに次のペアに席を譲る
  5. コーディング中のペア以外の人達は以下の様に何でも良いのでその場で口を出して良い。ただし、質問が優先されるべき。
  • 技術的な質問(このメソッド何なの?みたいな)
import Darwin
let string = "hello world"
var array = [UInt8]()
string.withCString { ptr in
print("strlen: \(strlen(ptr))")
let length = strlen(ptr)
var currentPtr = ptr
@ainame
ainame / string-api-changes.swift
Last active June 6, 2017 17:39
Is this a bug on the Swift4?
import Foundation
let array: [String?] = ["a", "b", "c", "e"]
print(array) // => [Optional("a"), Optional("b"), Optional("c"), Optional("e")]
let strings = array.flatMap { $0! }
print(type(of: strings)) // => Array<Character>
@ainame
ainame / 1.rb
Created January 15, 2012 04:23
RubyでRubyっぽい書き方をしよう初級編
# 1. for, whileを使わずにeachを使う
array = [1,2,3,4,5]
array.each do |e|
print e
end
#=> 12345
# テキストファイルを一気に読み込んで,
# 1行ごとにイテレート
textfile = File.open("a.txt").read
(defun newline-or-open-line ()
"newline-or-openline is a new command for merging C-m and C-o"
(interactive)
(let ((string-exists-before-cursor (string-match "[^\\\s\\\n\\\t]" (buffer-substring (point-at-bol) (point))))
(string-exists-after-cursor (string-match "[^\\\s\\\n\\\t]" (buffer-substring (point) (point-at-eol)))))
(cond ((or (eolp)
(not string-exists-after-cursor)
(and string-exists-before-cursor string-exists-after-cursor))
(progn (princ 1) (newline) (indent-according-to-mode)))
(t (progn (princ 2) (open-line 1) (indent-according-to-mode))))))
@ainame
ainame / file0.txt
Last active June 20, 2016 01:19
ActiveRecord::Enumで陥りがちなミスを避ける ref: http://qiita.com/ainame/items/a097558e74bf7d5087b9
class NotifyEndpoint
enum platform: [:apns, :gcm]
end