Skip to content

Instantly share code, notes, and snippets.

@shunsugai
shunsugai / browserfragment.java
Created August 30, 2012 05:29
ブラウザで閉じてまたもどっても再読み込みしないための設定
// Call from Activity
String url;
public void loadUrl(String url) {
if (mWebView == null) return;
if (this.url == null) {
mWebView.loadUrl(url);
this.url = url;
}
}
#かなり雑だけどこんな書き方もできる
class Bar
def initialize(options={})
@options = options
end
def method_missing(name, *args)
if name =~ /=$/
@options[name.to_s.chop.to_sym] = args.first
else
@shunsugai
shunsugai / inject.rb
Last active December 13, 2015 19:58
たぶんこれでOK
require 'pp'
data = [
{:code => 001, :item => {:name => 'jan'}},
{:code => 001, :item => {:name => 'jan'}},
{:code => 001, :item => {:name => 'aaa'}},
{:code => 002, :item => {:name => 'feb'}},
{:code => 002, :item => {:name => 'aab'}},
{:code => 003, :item => {:name => 'mar'}},
{:code => 003, :item => {:name => 'abb'}},
@shunsugai
shunsugai / lazy_demo.rb
Last active December 15, 2015 00:49
Ruby2.0の新機能、lazyを調査中。
# Benchmark of Enumerable#lazy.
# 'production.log' is a log of Rails application that size is 43.6MB.
require 'benchmark'
Benchmark.bm do |x|
x.report('normal') do
100.times do
File.open("./production.log") do |f|
f.each_line.select { |line| line =~ /RoutingError/ }.first(10)
tr = log --graph --all --format=\"%x09%C(cyan bold)%an%Creset%x09%C(yellow)%h%Creset %C(magenta reverse)%d%Creset %s\"
@shunsugai
shunsugai / init.el
Created June 3, 2014 15:22
emacs settings
;;
;; init.el
;;
;; -*- mode: emacs-lisp; coding: utf-8; indent-tabs-mode: nil -*-
;; Language
(set-language-environment 'Japanese)
;; Set alt as Meta key
@shunsugai
shunsugai / perm.go
Created December 25, 2014 14:59
Decrypt gesture.key with Golang.
package main
import (
"fmt"
"github.com/kokardy/listing"
"runtime"
"sync"
)
func main() {
@shunsugai
shunsugai / read-fingerprint-service.txt
Created June 29, 2015 12:52
FingerprintServiceを読んで気になったこと
http://tools.oesf.biz/android-MNC/xref/com/android/server/fingerprint/FingerprintService.java
=====
532 @Override
533 // Binder call
534 public void authenticate(final IBinder token, final long opId, final int groupId,
535 final IFingerprintServiceReceiver receiver, final int flags, String opPackageName) {
536 checkPermission(USE_FINGERPRINT);
537 if (!canUserFingerPrint(opPackageName)) {
538 return;
539 }
history = []
while history != [0, 0, 0, 0, 1] do
n = rand(2)
history.push(n)
history.shift if history.size > 5
puts n == 0 ? 'ズン' : 'ドコ'
end
puts 'キ・ヨ・シ!'
def zundoko(history = [])
return puts 'キ・ヨ・シ!' if history == ['ズン', 'ズン', 'ズン', 'ズン', 'ドコ']
zundoko(history.last(4) << ['ズン', 'ドコ'].sample.tap { |x| puts x })
end
zundoko