Skip to content

Instantly share code, notes, and snippets.

View krrrr38's full-sized avatar
💭
🍣

Ken Kaizu krrrr38

💭
🍣
View GitHub Profile
scala> case class InvalidData(i: Int)
defined class InvalidData
scala> def firstProcess(i: Int): Either[InvalidData, Int] = try{ Right(10 / i) } catch { case _: Throwable => Left(InvalidData(i)) }
firstProcess: (i: Int)Either[InvalidData,Int]
scala> def secondProcess(d: InvalidData): Either[InvalidData, Int] = try{ Right(10 + d.i) } catch { case _: Throwable => Left(InvalidData(d.i)) }
secondProcess: (d: InvalidData)Either[InvalidData,Int]
scala> for { a <- firstProcess(2).left; b <- secondProcess(a).right } yield b
# -*- coding: utf-8 -*-
##############################
##### Working with lists #####
##############################
def last(ls)
ls[-1]
end
@krrrr38
krrrr38 / gist:f94c54678bc02224a8f5
Created May 5, 2014 03:58
A Tour of Go - Exercise: Web Crawler
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
@krrrr38
krrrr38 / gist:5e9dce25e41e41ee57b9
Last active August 29, 2015 14:00
goroutineに出来ないのなんで
package main
import "fmt"
func rec(depth int, ch chan int) {
if depth > 3 {
return
} else {
ch <- depth
rec(depth+1, ch) // cannot be gorouting
@krrrr38
krrrr38 / gist:10515475
Last active August 29, 2015 13:59
サブルーチンプロトタイプに関数与えた際に勝手に付くuseとか
#!/usr/bin/env perl
use strict;
use utf8;
use Data::Dumper::Concise;
sub hoge(&;$) {
my $a = shift;
warn Dumper($a);
return $a->();
@krrrr38
krrrr38 / playvm
Last active August 29, 2015 13:58
play version manager based on svm(https://github.com/yuroyoro/svm)
#!/usr/bin/env bash
# Copyright (c) 2011 Tomohito Ozaki(yuroyoro)
# 2014 Ken Kaizu(krrrr38)
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
update
upgrade
tap homebrew/binary || true
tap phinze/homebrew-cask || true
install brew-cask
install ack
install android-sdk
install autoconf
@krrrr38
krrrr38 / xsrf-token.js
Last active January 1, 2016 21:19
Amon2 Flavor xsrf-token.js without jQuery
$self->write_file("$base/js/xsrf-token.js", <<'...');
var <% $module %> = <% $module %> || {};
<% $module %>.getXSRFToken = function() {
var token;
return function() {
if(token === undefined) {
var cookies = document.cookie.split(/\s*;\s*/);
for (var i=0,l=cookies.length; i<l; i++) {
var matched = cookies[i].match(/^XSRF-TOKEN=(.*)$/);
@krrrr38
krrrr38 / OAuthStack.java
Created December 27, 2013 00:56
volley + signpost
import com.android.volley.toolbox.HurlStack;
import oauth.signpost.OAuthConsumer;
import oauth.signpost.exception.OAuthCommunicationException;
import oauth.signpost.exception.OAuthExpectationFailedException;
import oauth.signpost.exception.OAuthMessageSignerException;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
@krrrr38
krrrr38 / GsonRequest.java
Last active December 25, 2015 10:29
どこかからの転用+α : volley + Gson
package com.example.external;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import com.android.volley.AuthFailureError;
import com.android.volley.NetworkResponse;
import com.android.volley.ParseError;
import com.android.volley.Request;
import com.android.volley.Response;