Skip to content

Instantly share code, notes, and snippets.

View YusukeHosonuma's full-sized avatar
🏠
Working from home

Yusuke Hosonuma YusukeHosonuma

🏠
Working from home
View GitHub Profile
@YusukeHosonuma
YusukeHosonuma / camelize.rb
Created November 9, 2015 14:15
Convert camelize string from underscore string.
def to_camelize(str)
s = str.split(/_/).map{|s| s.capitalize}.join('')
s[0] = s[0].downcase
s
end
underscore = 'apple_orange_banana'
camelize = to_camelize(underscore)
p camelize
type_map = {
'integer' => 'Int',
'string' => 'String',
}
type_string = 'integer'
type_swift = type_map[type_string]
p type_swift
@YusukeHosonuma
YusukeHosonuma / SequenceType+group.swift
Last active November 21, 2015 12:44
Three ways to implementation group() function.
import Foundation
extension SequenceType where Generator.Element : Equatable {
typealias E = Generator.Element
// use reduce()
func group() -> [[E]] {
let initial: [[E]] = []
let grouped = self.reduce(initial) { (var acc, x) -> [[E]] in
@YusukeHosonuma
YusukeHosonuma / swift_func_count.rb
Created November 21, 2015 15:38
Count swift functions
def swift_files(path, files)
Dir::glob(path + '/*').each {|fname|
if fname.include?('Test') # no search test dir & files
return
end
if FileTest.directory?(fname)
swift_files(fname, files)
else
if fname.include?('.swift')
files.push(fname)
// ==UserScript==
// @name GitHub Helper
// @namespace Yusuke.Hosonuma
// @description GitHubのコメントを全て開くボタンを追加
// @match https://github.com/*
// ==/UserScript==
(function(){
var target = document.getElementsByClassName('gh-header-actions');
var button = document.createElement('button');
button.innerHTML = 'Expand';
<html>
<head>
<!-- <link rel="stylesheet" type="text/css" href="sample.css"> -->
<script src="script.js"></script>
</head>
<body>
<select id="week">
<option>week1</option>
<option>week2</option>
<option>week3</option>
//
// MySubject.swift
// RxSwiftSample
//
// Created by Yusuke on 4/10/16.
// Copyright © 2016 Yusuke. All rights reserved.
//
import Foundation
@YusukeHosonuma
YusukeHosonuma / ViewController.swift
Last active April 11, 2016 15:10
RxSwift - Nofication sample
import UIKit
import RxSwift
import RxCocoa
class ViewController: UIViewController {
@IBOutlet weak var textView: UITextView!
@IBOutlet weak var countLabel: UILabel!
let disposeBag = DisposeBag()
@YusukeHosonuma
YusukeHosonuma / ValidationViewController.swift
Created April 11, 2016 16:32
RxSwift - Validation sample
import UIKit
import RxSwift
import RxCocoa
let requiredUserNameLength = 5
let requiredPasswordLength = 5
let limitUserNameLength = 20
class ValidationViewController: UIViewController {
@YusukeHosonuma
YusukeHosonuma / rle.hs
Last active May 5, 2016 07:44
RL encode/decode with doctest
module RLE where
import Data.List ( group, groupBy )
-- | ランレングス圧縮
--
-- >>> rle "AAABBCCCCD"
-- "A3B2C4D1"
--
-- >>> rle "AAAAAAAAAAB"