Skip to content

Instantly share code, notes, and snippets.

View freakhill's full-sized avatar

freakhill

  • tokyo
View GitHub Profile
require 'ripper'
require 'sourcify'
def lines(source)
Enumerator.new do |out|
source.split("\n")[1..-2].reduce("") do |buffer, line|
buffer << "\n#{line}"
Ripper.sexp_raw(buffer) ? (out << buffer) && "" : buffer
end
end
@freakhill
freakhill / list_comprehension.rb
Last active December 17, 2015 06:19
having fun with "haskell like list comprehension in ruby" - https://gist.github.com/andkerosine/3356675
#!/usr/bin/env ruby-head
class VeryBasicObject < BasicObject
undef :==
undef :!=
undef :!
end
class Captured < VeryBasicObject
def method_missing meth, *args
@freakhill
freakhill / rename.rb
Last active December 19, 2015 02:19
rename pdf files i downloader around the internet
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# easy to break use at your own risk
# this script renames pdf files in a folder (and subfoler) (on unixy machines)
# with a naive heuristic to find the title (that unfortunately is never in the *title* metadata)
require 'pdf-reader'
@freakhill
freakhill / epub_to_mobi_gutenberg.rb
Created June 28, 2013 07:03
working on redownloading my gutenberg epub file to mobi files
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
`find "/Users/freakhill/Dropbox/アプリ/gutenberg" -name "*.epub"`.split("\n").each do |f|
File.basename(f) =~ /^(.*)\.epub$/
title = $1
if File.exists? File.join(File.dirname(f), "#{title}.mobi")
puts "skipping #{$1}"
next
end
@freakhill
freakhill / typetag_to_runtime_class.scala
Last active December 22, 2015 12:38
Compare static TypeTag to runtime Class
import scala.reflect.runtime.universe._
class A[E](e:E)(implicit t: TypeTag[E]){
def c(o:Any) = {
val TypeRef(_, klass_symbol, _) = t.tpe
println(s"ClassSymbol extracted from TypeTag[E] '${klass_symbol.asClass}' : ClassSymbol")
println(s"Class extracted from o:Any parameter = '${o.getClass}' : Class[??]")
runtimeMirror(getClass.getClassLoader).runtimeClass(klass_symbol.asClass) == o.getClass
}
}
@freakhill
freakhill / CouponActivity.java
Last active December 26, 2015 02:39
Wakuwaku SDK client
package jp.ne.wakuwaku.test;
import jp.ne.wakuwaku.sdk.Wakuwaku;
import jp.ne.wakuwaku.sdk.Wakuwaku.Coupon;
import jp.ne.wakuwaku.sdk.Wakuwaku.InitException;
import jp.ne.wakuwaku.sdk.Wakuwaku.NoEmailProvidedException;
import jp.ne.wakuwaku.sdk.Wakuwaku.NoWalletInstalledException;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
@freakhill
freakhill / .gitignore
Last active December 24, 2016 10:11
emacs init script
*~
.*
*.dat
*.eld
.smex-items
.emacs_workgroups_*
tmp*
places
ede-projects.*
ac-dict/
@freakhill
freakhill / core.clj
Last active August 29, 2015 14:06
problem with optional parameters in protocols with core typed
(ns test.core
(:require [ clojure.core.typed :as t ]))
(t/ann-protocol P2
olol (t/IFn [P2 Kw * -> t/Any]))
(t/defprotocol> P2
(olol [this & rest]))
(t/ann-record R2 [])
(defrecord R2 []
@freakhill
freakhill / .gitignore
Last active August 29, 2015 14:27
core typed protocol check method too large
/target
/classes
/checkouts
pom.xml
pom.xml.asc
*.jar
*.class
/.lein-*
/.nrepl-port
@freakhill
freakhill / .gitignore
Last active November 19, 2015 06:01
leiningen public profile stuff
self-installs