Skip to content

Instantly share code, notes, and snippets.

@ywjno
ywjno / image_replacer.js
Created March 18, 2012 03:39 — forked from Sai/image_replacer.js
Web@2x
if (typeof (AC) === "undefined") {
AC = {}
}
AC.ImageReplacer = Class.create({
_defaultOptions: {
listenToSwapView: true,
filenameRegex: /(.*)(\.[a-z]{3}($|#.*|\?.*))/i,
filenameInsert: "_☃x",
ignoreCheck: /(^http:\/\/movies\.apple\.com\/|\/105\/|\/global\/elements\/quicktime\/|_(([2-9]|[1-9][0-9]+)x|nohires)(\.[a-z]{3})($|#.*|\?.*))/i,
attribute: "data-hires",
@ywjno
ywjno / mechanize_test.rb
Created May 9, 2012 06:47
login github used mechanize
# encoding: utf-8
require 'rubygems'
require 'mechanize'
# Create a new mechanize object
agent = Mechanize.new
# set verify mode becaust the website used https
agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
@ywjno
ywjno / scheduler_test.rb
Created May 9, 2012 07:26
test scheduler
# encoding: utf-8
require 'rubygems'
require 'rufus/scheduler'
scheduler = Rufus::Scheduler.start_new
puts "start work at #{Time.new.strftime('%Y-%m-%d %H:%M:%S')}"
scheduler.every '1m' do
@ywjno
ywjno / rss_test.rb
Created May 9, 2012 07:41
read rss content used ruby
# encoding: utf-8
require 'rss'
require 'open-uri'
# url or local file
source = "http://snippets.aktagon.com/main.rss"
# and ths src when if url is https
require 'openssl'
@ywjno
ywjno / time_parse_test.rb
Created May 9, 2012 08:02
test Time.parse and Date.strptime method
# encoding: utf-8
require 'date'
require 'time'
time = Time.parse("Wed, 9 May 2012 16:00:00 +0800")
# the src is like
#time = Time.parse("2012.05.09 16:00 +08:00")
puts time # 2012-05-09 16:00:00 +0800
@ywjno
ywjno / gist:2642898
Created May 9, 2012 08:15
split text content to html content(p tag and br tag)
include Rack::Utils
alias_method :h, :escape_html
def split_content(string)
show_html = ""
p_content = []
lines = string.split("\n")
lines.each_with_index do |line, index|
new_line = h(line.strip)
if index != lines.length - 1
@ywjno
ywjno / gist:2887170
Created June 7, 2012 07:28
doesn't escape when used to_json method
something.to_json.gsub(/\\u([0-9a-z]{4})/){|s| [$1.to_i(16)].pack("U")}
@ywjno
ywjno / domains.rb
Created July 6, 2012 07:38
get you would like DomainsList from pool.com
# encoding: utf-8
# * First, you would to got PoolDeletingDomainsList.txt from [here](http://www.pool.com/Downloads/PoolDeletingDomainsList.zip)
# * Unzip this zip file, get PoolDeletingDomainsList.txt file, put the txt file in this file on one folder
# * In shell or cmd, run `ruby domains.rb`, you will get you would like domains list in DomainsList.txt file
# * There are 6 length domain, so change the length if you would.
class Domains
def self.would_domains(input_file = "PoolDeletingDomainsList.txt", output_file = "DomainsList.txt")
@ywjno
ywjno / gist:3088388
Created July 11, 2012 06:28
Don't output assers logs in Rails 3.2.x
# add this code in config/environments/development.rb
Rails::Rack::Logger.class_eval do
def call_with_quiet_assets(env)
previous_level = Rails.logger.level
Rails.logger.level = Logger::ERROR if env['PATH_INFO'].index("/assets/") == 0
call_without_quiet_assets(env).tap do
Rails.logger.level = previous_level
end
end
@ywjno
ywjno / create_getter_setter_methods_for_java.rb
Created July 18, 2012 07:58
create getter setter methods for java, by writing order for this java bean
#encoding: utf-8
require 'find'
class CreateGetterSetterMethodsForJava
def initialize
@work_path = File.dirname(File.expand_path(__FILE__))
if ARGV.length != 0
if File.file?(ARGV[0])