Skip to content

Instantly share code, notes, and snippets.

View moaible's full-sized avatar

Hiromi Motodera moaible

View GitHub Profile
@moaible
moaible / Also.swift
Created October 20, 2018 12:57
Also.swift
infix operator =< : AlsoPrecedence
precedencegroup AlsoPrecedence {
higherThan: AssignmentPrecedence
associativity: left
}
public func =<<T>(lhs: T, rhs: (T) throws -> Void) rethrows -> T {
try rhs(lhs)
return lhs
@moaible
moaible / ScopeBenchmark.swift
Last active October 3, 2018 08:09
ScopeBenchmark.swift
import Foundation
public final class ScopeBenchmark {
private let startTime = Date()
private let UUID = Foundation.UUID().uuidString.prefix(6)
private var identifier = ""
@moaible
moaible / .gitconfig(alias)
Created September 30, 2018 14:09
dotfiles
[alias]
co = checkout
st = status
ci = commit -a
d = diff
dc = diff --cached
br = branch
s = status --short --branch
rv = remote --verbose
graph = log --graph --date=short --decorate=short --pretty=format:'%C(red)%h %C(reset)-%C(yellow)%d %Creset%s %Cgreen(%cr) %C(bold blue)<%an>%Creset'
use std::io;
fn main() {
println!("{}", read_line())
}
fn read_line() -> String {
let mut line = String::new();
io::stdin().read_line(&mut line)
.expect("Failed to read line");
@moaible
moaible / breadcrumb.min.js
Last active May 4, 2018 07:56
breadcrumb.min.js
function remapBreadcrumb(a){new_breadcrumb_html="";for(var b=0;b<a.length;b++){url_category=[];for(var c=0;c<=b;c++)url_category[c]=a[c];new_breadcrumb_html+='<span class="breadcrumb-child" itemprop="child" itemscope itemtype="http://data-vocabulary.org/Breadcrumb"><a class="breadcrumb-child-link" href="http://'+host+"/archive/category/"+url_category.join("#")+'" itemprop="url"><span itemprop="title">'+a[b]+"</span></a></span>",b+1<a.length&&(new_breadcrumb_html+='<span class="breadcrumb-gt"> &gt;</span>')}""!=new_breadcrumb_html&&$("#top-box > div.breadcrumb > div.breadcrumb-inner > span.breadcrumb-child:first").prop("outerHTML",new_breadcrumb_html)}function remapArticleCategory(a){for(var b=0;"undefined"!=typeof a[b+1]&&a[b+1].text.includes("#");)b+=1;breadcrumb_array=a[b].text.split("#"),remapBreadcrumb(breadcrumb_array),category_num=a.length;for(var c=0;c<category_num;c++)category_branch=a[c].text.split("#"),a[c].text=category_branch[category_branch.length-1]}function remapCategoryBreadcrumb(a){new_breadc
@moaible
moaible / category_archive.min.js
Last active May 6, 2018 04:21
はてブロ-カテゴリ-階層化 (-) -> ($) 対応
function processArchive(a,b,c){for(flag=!0;a<$all_li.length;){if($li=$($all_li[a]),$a=$li.find("a"),category_name=$a.text(),breadcrumb=category_name.split("#"),level=breadcrumb.length,1==level&&a>0&&$li.attr("class","on-border"),level<b)return b>2&&$($all_li[a-1]).css("padding-bottom","0px"),a-1;level==b?($a.text(breadcrumb[level-1]),null!=c?$li.appendTo(c):($opend_span=$('<span class="hatena-breadcrumb-plus-toggle-button" id="opend-'+a+'" style="color: #454545">▼</span>'),$closed_span=$('<span class="hatena-breadcrumb-plus-toggle-button" id="closed-'+a+'" style="color: #454545">▶</span>'),$closed_span.css("visibility","hidden"),$opend_span.css("display","none"),$li.prepend($closed_span),$li.prepend($opend_span))):(id=a-1,ulid="hatena-breadcrumb-plus-toggle-"+id,$new_ul=$('<ul id="'+ulid+'" type="square"></ul>'),level>2?$new_ul.attr("class","hatena-breadcrumb-plus-child2"):($new_ul.attr("class","hatena-breadcrumb-plus-child1"),$new_ul.css("display","none")),$($all_li[id]).append($new_ul),$("#closed-"+id).css(
@moaible
moaible / ReadLines.swift
Last active February 15, 2018 22:43
Competitive Swift Codes
func readLines() -> [String] {
var results = [String]()
while(true) {
guard let readLine = readLine() else {
break
}
results.append(readLine)
}
return results
}
/// Uses `JSONSerialization` to create a JSON representation of the parameters object, which is set as the body of the
/// request. The `Content-Type` HTTP header field of an encoded request is set to `application/json; charset=utf-8`.
public struct JSONWithUTF8CharsetEncoding: ParameterEncoding {
// MARK: Properties
/// Returns a `JSONEncoding` instance with default writing options.
public static var `default`: JSONEncoding { return JSONEncoding() }
/// Returns a `JSONEncoding` instance with `.prettyPrinted` writing options.
@moaible
moaible / Geofence.swift
Last active December 16, 2017 16:33
Geofence.swift
import CoreLocation
import CoreMotion
struct Geofence {
typealias Degreese = Double
typealias Radius = Double
var identifier: String
var radius: Radius
@moaible
moaible / Example.swift
Last active December 15, 2017 01:12
GoogleAnalytics.swift
struct ExampleSender: GoogleAnalyticsSendable {
static var googleAnalyticsTrackingId: String {
"{tracking id}"
}
}
// Usage
ExampleSender.sendEventTracking(category: "example", action: "action")