Skip to content

Instantly share code, notes, and snippets.

@y-ogi
y-ogi / insert_accessibility.py
Last active December 10, 2015 11:12
Insert accessibility to storyboard
# -*- coding: utf-8 -*-
import optparse
import xml.etree.ElementTree as ET
targets = ['button', 'label', 'textField']
def main(storyboard):
tree = ET.parse(storyboard)
for target in targets:
for element in tree.getroot().iter(target):
@y-ogi
y-ogi / gist:21a46fe0ab3ad85339c3
Created March 30, 2015 02:32
Create ViewController from storyboard programmatically
class func viewController() -> UIViewController {
let vc = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()).instantiateViewControllerWithIdentifier("ViewController") as UIViewController
return vc
}
@y-ogi
y-ogi / gist:5cb62e241873ca676da2
Last active August 29, 2015 14:07
Using FontAwesome for RightBarButtonItem with Swift
let textAttributes = [
NSFontAttributeName: UIFont(name: "FontAwesome", size: 18),
NSForegroundColorAttributeName: UIColor.redColor()
]
let rightBarButtonItem = UIBarButtonItem(title: "Search", style: .Plain, target: nil, action: nil)
rightBarButtonItem.setTitleTextAttributes(textAttributes, forState: .Normal)
rightBarButtonItem.title = NSString.awesomeIcon(FaSearch)
self.navigationItem.rightBarButtonItem = rightBarButtonItem
@y-ogi
y-ogi / blur.swift
Created October 5, 2014 14:58
how to add blur effect to view
func applyBlur(view: UIView) {
var visualEffectView = UIVisualEffectView(effect: UIBlurEffect(style: .Light)) as UIVisualEffectView
visualEffectView.frame = view.bounds
view.addSubview(visualEffectView)
}
@y-ogi
y-ogi / code2rgb.py
Created June 13, 2014 03:12
Python script for converting html color code to rgb
import re
import sys
import optparse
def main(color):
print "R:%d G:%d B:%d" % tuple([int(x, 16) for x in re.findall('[a-fA-F0-9]{2}', color[1:] if color[0] == '#' else color)])
if __name__ == '__main__':
usage = "Usage: %prog code"
@y-ogi
y-ogi / code2uicolor.py
Created June 13, 2014 03:07
python script for converting html color code to UIColor
#!/usr/bin/env python
import re
import sys
import optparse
def main(color):
print "[UIColor colorWithRed:%.3f green:%.3f blue:%.3f alpha:1.f]" % tuple([round(int(x, 16) / 255., 3) for x in re.findall('[a-fA-F0-9]{2}', color[1:] if color[0] == '#' else color)])
if __name__ == '__main__':
usage = "Usage: %prog code"
@y-ogi
y-ogi / wercker.yml
Created May 31, 2014 04:24
wercker.yml to deploy heroku
box: wercker/nodejs
# Build definition
build:
# The steps that will be executed on build
steps:
# A step that executes `npm install` command
- npm-install
# A step that executes `npm test` command
#- npm-test
- add-to-known_hosts:
@y-ogi
y-ogi / gist:8121223
Created December 25, 2013 08:04
xib -> strings & strings -> xib
# xib -> strings
ibtool --generate-strings-file en.lproj/HogeViewController.strings en.lproj/HogeViewController.xib
# strings -> xib
ibtool --strings-file ja.lproj/HogeViewController.strings en.lproj/HogeViewController.xib --write ja.lproj/HogeViewController.xib
@y-ogi
y-ogi / gist:8121217
Created December 25, 2013 08:03
Objective-Cのコード上の日本語文字列を抜き出す(大体)
find ./ -name "*.m" | xargs cat | python -c "import sys,re;print('\n'.join([s for s in re.compile(r'@\"([^\"]+)\"').findall(sys.stdin.read()) if re.search(r'[^\x01-\x7E]', s)]))"
@y-ogi
y-ogi / sample-daemon.py
Created October 22, 2013 10:27
python daemon sample
# -*- coding: utf-8 -*-
import sys
import time
import argparse
from daemon import DaemonContext
from daemon.pidfile import PIDLockFile
def daemon_loop(interval=600):