Skip to content

Instantly share code, notes, and snippets.

View kengos's full-sized avatar

Kengo Suzuki kengos

  • Hamamatsu Japan
View GitHub Profile
@kengos
kengos / gist:2464207
Created April 22, 2012 13:47
ActiveEnum i18n support patch
# In your config/initializers/active_enum.rb
# @see https://github.com/adzap/active_enum/pull/4
# @example
# * ja.yml
# active_enum:
# user:
# sex:
# male: '男性'
# female: '女性'
# * user.rb
<script type="text/javascript">
//<![CDATA[
$(function(){
$("body a[href^='http://']").on("click", function(){
url = $(this).attr('href');
if(url.indexOf($(location).attr('hostname')) == -1)
{
_gaq.push(['_trackEvent', 'Link', $(location).attr('href'), url]);
}
});
@kengos
kengos / sample1.rb
Last active May 6, 2019 01:50
Ruby benchmark
require 'benchmark'
n = %w(a b c d e f g h i j k l m n o p q r s t u v w x y z)
Benchmark.bm do |bm|
bm.report("each_with_index:") {
100000.times do
n.each_with_index do |o,i|
x = [o, i]
end
end
#!/bin/bash
PATH=/sbin:/usr/sbin:/bin:/usr/bin
SSH=33843
HTTP=80,443
IDENT=113
NTP=123
MYSQL=3306
DHCP=67,68
initialize()
@kengos
kengos / Usage.md
Created September 30, 2015 03:50
phpdebug
@kengos
kengos / shuffle!
Last active November 12, 2015 12:20
浜松ruby#58 その1
#!/usr/bin/env ruby
class Model
attr_accessor :a, :b, :c, :d, :e, :f, :g, :h
def attributes(arr)
@a = arr[0]
@b = arr[1]
@c = arr[2]
@d = arr[3]
@kengos
kengos / Genetic Algorithms
Created November 12, 2015 12:20
浜松ruby#58 その2
#!/usr/bin/env ruby
class Model
attr_accessor :genomes
def initialize(genomes)
@genomes = genomes
end
def score
@kengos
kengos / 1-100で同じ問題
Created November 12, 2015 13:39
浜松Ruby#58 その3
#!/usr/bin/env ruby
class Model
attr_accessor :genomes
def initialize(genomes)
@genomes = genomes
end
def score
@kengos
kengos / cache.js
Created December 4, 2015 00:08 — forked from bshamric/cache.js
I like phantomjs, but it doesn't directly support getting images from webpages without requesting them separately like in casperjs. I went through QTNetworking code in the phantomjs repo until I figured out where the cache was. To use this, have all three files in the same directory. Then modify test.js for whatever you need. Call phantom js wit…
var fs = require('fs');
//this is the path that QTNetwork classes uses for caching files for it's http client
//the path should be the one that has 16 folders labeled 0,1,2,3,...,F
exports.cachePath = '/path/to/phantomjs/cache/data/folder';
//this is the extension used for files in the cache path
exports.cacheExtension = "d";
//the resources that are to be saved
@kengos
kengos / NC3BI3DNMR2PGEOOMP2NKXQGSAKMS7GYRKVA5CSZ_incoming.tsv
Created January 30, 2018 07:01
NC3BI3DNMR2PGEOOMP2NKXQGSAKMS7GYRKVA5CSZ_incoming_and_outgoing
We can't make this file beautiful and searchable because it's too large.
2018-1-30 13:53:45 1598242 257 NDN2L3HVD36ABYEH24NXBZA636VFTILNH5U3LY6K NC3BI3DNMR2PGEOOMP2NKXQGSAKMS7GYRKVA5CSZ 39303266313136643662323931393661 10
2018-1-30 01:09:29 1596400 4100 NAGJG3QFWYZ37LMI7IQPSGQNYADGSJZGJRD2DIYA NC3BI3DNMR2PGEOOMP2NKXQGSAKMS7GYRKVA5CSZ 36303830316636306637336563646263 25
2018-1-29 17:47:36 1594547 257 ND5HNZIIWA4IRCL55YVMWZEEWWZVSQ6HB4CP2Q4R NC3BI3DNMR2PGEOOMP2NKXQGSAKMS7GYRKVA5CSZ 4e42424a5144565a4b50454f4a4c434745493346515133494d375a564f4c4f565a3652434c465656 9000
2018-1-29 08:46:22 1593197 257 NCOE7HHGYE4ZG3NKYY4LM477RW2QPTPAIYZPBYIX NC3BI3DNMR2PGEOOMP2NKXQGSAKMS7GYRKVA5CSZ 33306137393632316637633965313338 5
2018-1-29 08:37:14 1593183 257 NCOE7HHGYE4ZG3NKYY4LM477RW2QPTPAIYZPBYIX NC3BI3DNMR2PGEOOMP2NKXQGSAKMS7GYRKVA5CSZ 5
2018-1-26 23:37:20 1578866 257 NCP7UH5BT5OHPAWPFFVNR2453BNODJUZJ6777N3N NC3BI3DNMR2PGEOOMP2NKXQGSAKMS7GYRKVA5CSZ 61383734386330336433333130663635 509
2018-1-26 22:28:12 1578388 257 NDMTUFGCJP2YO7FJAVIWEUTCHVKO5UF3L7OD2AQH NC3BI3DNMR2PGEOOMP2NKXQGSAKMS7GYRKVA5CSZ