Skip to content

Instantly share code, notes, and snippets.

@albb0920
albb0920 / TestView.java
Created February 28, 2011 11:57
MetaKeyKeyListener example
package tw.loli.inputTest;
import android.content.Context;
import android.graphics.Color;
import android.text.Editable;
import android.text.InputType;
import android.text.method.MetaKeyKeyListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.inputmethod.BaseInputConnection;
@albb0920
albb0920 / gist:980153
Created May 19, 2011 03:50
Simple sudo under net/ssh
#!/usr/local/bin/ruby19
require 'rubygems'
require 'net/ssh'
PASSWORD = '.....'
def shell
Net::SSH.start('127.0.0.1','user',:password => PASSWORD) do |ssh|
yield(SudoWrapper.new(ssh, PASSWORD))
end
end
@albb0920
albb0920 / rails_admin.zh-TW.yml
Created March 8, 2012 16:11
Traditional Chinese translation for RailsAdmin
zh-TW:
admin:
home:
name: "網站首頁"
pagination:
previous: "« 前頁"
next: "次頁 »"
truncate: "…"
misc:
filter_date_format: "mm/dd/yy" # a combination of 'dd', 'mm' and 'yy' with any delimiter. No other interpolation will be done!
@albb0920
albb0920 / book.rb
Created August 15, 2012 17:29
update or create nested association
class Book < ActiveRecord::Base
attr_accessible :authors_attributes
has_and_belongs_to_many :authors
accepts_nested_attributes_for :authors
def authors_attributes=(new_authors)
self.authors = new_authors.collect do |author_attrs|
if author_id = author_attrs.delete(:id)
author = Author.find(author_id) rescue nil
@albb0920
albb0920 / ruten.php
Created August 16, 2012 16:23
Ruten search crawler v2
<?php
$key = get_ruten_key();
$good_url = 'http://goods.ruten.com.tw/item/show?21109087634023';
$context = stream_context_create(array(
'http' => array(
'header' =>
"User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.77 Safari/537.1\r\n".
"Referer:$good_url\r\n".
"Cookie: _ts_id=$key\r\n"
@albb0920
albb0920 / rbenv_bash
Created October 26, 2012 09:20
If you use whenever and find bash -l -c won't load rbenv, here's a hacky way to fix it.
#!/bin/bash
# Save this file to /usr/bin/rbenv.bash, chmod +x it, and set SHELL variable in crontab to this.
export RBENV_ROOT=/usr/local/rbenv
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)";
bash "$@"
@albb0920
albb0920 / hooks.php
Created December 23, 2014 17:44
Wordpress debug snippets
<?php
$hooks = array();
add_action('all', function($hook){
global $hooks;
$hooks[]= $hook;
});
add_action('admin_print_scripts', function(){
global $hooks;
echo "<script>console.log('hooks:'); console.log('".implode(',',array_unique($hooks))."');</script>";
We can't make this file beautiful and searchable because it's too large.
10001,臺北市中正區,中山南路
10002,臺北市中正區,中山南路
10005,臺北市中正區,重慶南路一段
10006,臺北市中正區,重慶南路一段
10007,臺北市中正區,重慶南路一段
10008,臺北市中正區,重慶南路一段
10009,臺北市中正區,衡陽路
10012,臺北市中正區,忠孝西路一段
10013,臺北市中正區,羅斯福路一段
10014,臺北市中正區,南海路
@albb0920
albb0920 / poc.rb
Last active September 23, 2016 20:00
Inject method accessor for specific Hash instance PoC
# ====
# PoC: dot access to specific hash instance
# ===
x = {a: 1, b:2}
# override method_missing
original_method_missing = x.method(:method_missing)
x.define_singleton_method :method_missing do|name, *args, &block|
return x[name] if x.key? name
@albb0920
albb0920 / snip.coffee
Created October 3, 2016 03:19
bootstrap tab thing
$('#settings-tabs a[data-target]').click (e)->
e.stopPropagation()
e.preventDefault()
history.pushState(null, null, $(this).attr('href'))
$('#settings-tabs .active').removeClass('active')
$(this).closest('li').addClass('active')
active_pane = $($(this).data('target'))
active_pane.closest('.tab-content').find('.tab-pane.active').removeC