Skip to content

Instantly share code, notes, and snippets.

View tmyymmt's full-sized avatar

Tomoya Yamamoto tmyymmt

View GitHub Profile
@tmyymmt
tmyymmt / main.xml
Created April 3, 2012 01:36
res/layout/main.xml
<nu.mine.tmyymmt.android.widget.RetractiveHorizontalScrollView>
<LinearLayout>
<TextView />
<TextView android:id="@+id/child_content" />
<TextView />
</LinearLayout>
</nu.mine.tmyymmt.android.widget.RetractiveHorizontalScrollView>
@tmyymmt
tmyymmt / HexBytesUtil.scala
Created September 14, 2012 09:58
hex2bytes and bytes2hex
object HexBytesUtil {
def hex2bytes(hex: String): Array[Byte] = {
if(hex.contains(" ")){
hex.split(" ").map(Integer.parseInt(_, 16).toByte)
} else if(hex.contains("-")){
hex.split("-").map(Integer.parseInt(_, 16).toByte)
} else {
hex.sliding(2,2).toArray.map(Integer.parseInt(_, 16).toByte)
}
@tmyymmt
tmyymmt / HexBytesUtil.scala
Created September 15, 2012 09:37
hex2bytes and bytes2hex fixed
object HexBytesUtil {
def hex2bytes(hex: String): Array[Byte] = {
hex.replaceAll("[^0-9A-Fa-f]", "").sliding(2, 2).toArray.map(Integer.parseInt(_, 16).toByte)
}
def bytes2hex(bytes: Array[Byte], sep: Option[String] = None): String = {
sep match {
case None => bytes.map("%02x".format(_)).mkString
case _ => bytes.map("%02x".format(_)).mkString(sep.get)
@tmyymmt
tmyymmt / SolutionForNestedMatchStatements.scala
Created September 15, 2012 18:56
Solution for nested match statements
// see https://gist.github.com/2382341
// scalaz for only solution3
import scalaz._
import Scalaz._
object SolutionForMultiNestedMatchforMyStudy {
def f(num: Int): Option[Int] = {
num match {
@tmyymmt
tmyymmt / monad1.java
Created September 16, 2012 16:45
Monad 1
if (foo != null) {
Bar bar = foo.getBar();
if (bar != null) {
Baz baz = bar.getBaz();
if (baz != null)
return baz.compute();
else
return null;
}
else
for {
foo <- maybeFoo
bar <- foo.bar
baz <- bar.baz
} yield baz.compute
def compute1(maybeFoo: Option[Foo]): Option[Int] =
for {
foo <- maybeFoo
bar <- foo.bar
baz <- bar.baz
} yield baz.compute
// for compute2
import scalaz._
import Scalaz._
@tmyymmt
tmyymmt / grep-specs2-unit-selected-buffer.l
Created October 11, 2012 15:00
Grep description of specs2 unit specification in selected buffer on xyzzy
; Grep description of specs2 unit specification in selected buffer on xyzzy
; Please copy & paste following code at your .xyzzy
; Usage: M-x grep-specs2-unit-selected-buffer
(defun grep-specs2-unit-selected-buffer ()
(interactive)
(grep " should \\| in " (selected-buffer)))
@tmyymmt
tmyymmt / init.el
Created November 7, 2012 16:25
init.el for cocoa emacs
; css-mode
(defun coding-style-css ()
(setq css-indent-offset 2))
(add-hook 'css-mode-hook 'coding-style-css)
;
(setq truncate-lines t)
(setq truncate-partial-width-windows t)
@tmyymmt
tmyymmt / .tmux.conf
Created November 12, 2012 06:39
.tmux.conf for osx
bind -r ^ resize-pane -R 5
bind -r C-^ resize-pane -L 5
bind 0 kill-pane
bind 2 split-window -v
bind 3 split-window -h