Skip to content

Instantly share code, notes, and snippets.

View ShingoFukuyama's full-sized avatar

Shingo Fukuyama ShingoFukuyama

  • Japan
View GitHub Profile
@oozoofrog
oozoofrog / Castable.swift
Last active August 20, 2016 12:03
freeing Unsafe<Mutable>Pointer casing
protocol Castable {}
protocol UnsafePointerProtocol: NilLiteralConvertible {
associatedtype Memory
init(nilLiteral: ())
init<Memory>(_ from: UnsafeMutablePointer<Memory>)
init<Memory>(_ from: UnsafePointer<Memory>)
var memory: Memory { get }
func mutable<M>() -> UnsafeMutablePointer<M>
@onevcat
onevcat / nstimer_break_retain.swift
Created September 28, 2015 03:34
NSTimer extension which breaks the retain cycle in Swift.
private class Block<T> {
let f : T
init (_ f: T) { self.f = f }
}
extension NSTimer {
static func xxx_scheduledTimerWithTimeInterval(ti: NSTimeInterval, block: ()->(), repeats: Bool) -> NSTimer {
return self.scheduledTimerWithTimeInterval(ti, target:
self, selector: "xxx_blcokInvoke:", userInfo: Block(block), repeats: repeats)
}
@perlmunger
perlmunger / Implemenation.swift
Last active March 3, 2022 01:45
Swift NSURLSession Check File Last Modified Date With HEAD Request
func checkShouldDownloadFileAtLocation(urlString:String, completion:((shouldDownload:Bool) -> ())?) {
var request = NSMutableURLRequest(URL: NSURL(string: urlString)!)
request.HTTPMethod = "HEAD"
var session = NSURLSession.sharedSession()
var err: NSError?
var task = session.dataTaskWithRequest(request, completionHandler: { [weak self] data, response, error -> Void in
if let strongSelf = self {
var isModified = false
@samirahmed
samirahmed / errorcodes.m
Created November 13, 2014 18:13
NSURLErrorDomain codes
kCFURLErrorUnknown = -998,
kCFURLErrorCancelled = -999,
kCFURLErrorBadURL = -1000,
kCFURLErrorTimedOut = -1001,
kCFURLErrorUnsupportedURL = -1002,
kCFURLErrorCannotFindHost = -1003,
kCFURLErrorCannotConnectToHost = -1004,
kCFURLErrorNetworkConnectionLost = -1005,
kCFURLErrorDNSLookupFailed = -1006,
kCFURLErrorHTTPTooManyRedirects = -1007,
@staltz
staltz / introrx.md
Last active July 2, 2024 03:45
The introduction to Reactive Programming you've been missing
<?xml version="1.0"?>
<root>
<item>
<name>Change Return Key R</name>
<item>
<name>Return to Command_R</name>
<identifier>remap.return2commandR</identifier>
<autogen>__KeyToKey__ KeyCode::RETURN, KeyCode::COMMAND_R</autogen>
</item>
<item>
anonymous
anonymous / emacs24_3_inline_memleak.sh
Created January 22, 2014 04:06
emacs 24.3でdistnotedを暴走させないパッチ+inlineパッチのビルド手順です。sakito.jpの手順を修正したものです。
EMACS_VER=24.3
curl -O http://ftp.gnu.org/pub/gnu/emacs/emacs-${EMACS_VER}.tar.gz
curl -O https://gist.github.com/anonymous/8553178/raw/c0ddb67b6e92da35a815d3465c633e036df1a105/emacs.memory.leak.aka.distnoted.patch.diff
svn co http://svn.sourceforge.jp/svnroot/macemacsjp/inline_patch/trunk inline_patch
tar xvfz emacs-${EMACS_VER}.tar.gz
cd emacs-${EMACS_VER}
@yuutayamada
yuutayamada / use-mykie-el-with multiple-cursor.el
Created January 7, 2014 19:09
Use this snippet if you encountered some trouble when you are using mykie.el with multiple-cursor.el
(eval-when-compile (require 'cl))
(defun* my/set-keybinds (map &rest key-and-func)
(loop with use-keymap = (keymapp map)
for i from 0 to (1- (length key-and-func)) by 2
for key = (nth i key-and-func)
for formatted-key = (if (vectorp key) key (kbd key))
for func = (nth (1+ i) key-and-func)
if use-keymap
do (define-key map formatted-key func)
@hiroshido
hiroshido / file0.txt
Created November 28, 2013 06:44
UIColorでRGBをHex(16進数)で指定出来てアルファもキメちゃうマクロ ref: http://qiita.com/unamu/items/61ec0a99419d5afafdb9
//RGB color macro
#define UIColorFromRGB(rgbValue) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]
//RGB color macro with alpha
#define UIColorFromRGBWithAlpha(rgbValue,a) [UIColor \
colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 \
green:((float)((rgbValue & 0xFF00) >> 8))/255.0 \
@sabof
sabof / gist:7363048
Created November 7, 2013 22:35
es-make-minibuffer-frame
(defun es-make-minibuffer-frame ()
(interactive)
(let* (( last-recursion-depth )
( frame (make-frame '((width . 60)
(height . 4)
(minibuffer . only)
(title . "Emacs-Minibuffer"))))
( enable-recursive-minibuffers t)
;; Runs when going down a level, or when entering a prompt. Not ideal
( minibuffer-exit-hook (list (lambda ()