Skip to content

Instantly share code, notes, and snippets.

View marsz's full-sized avatar
💩
Diving

MarsZ Chen marsz

💩
Diving
View GitHub Profile
@marsz
marsz / example_group.rb
Created October 20, 2016 16:02
Monkey patching of RSpec example gruop for document output with gherkin language format
# put this file to spec/support/
module RSpec
module Core
class ExampleGroup
def self.Then(*args, &block)
args[0] = "Then #{args[0]}" if args[0].is_a?(String)
it(*args, &block)
end
def self.Given(*args, &block)
@marsz
marsz / astro.rb
Created July 31, 2013 07:56
星座判斷
def within_date?(date, from_date, to_date)
date = date.to_date
(Time.parse("#{date.year}/#{from_date}").to_date..Time.parse("#{date.year}/#{to_date}").to_date).include?(date)
end
date = Time.parse("1982-3-30")
puts within_date?(date, "3/1", "3/30").inspect
puts within_date?(date, "2/1", "2/28").inspect
if within_date?(date, "3/1", "3/30")
@marsz
marsz / .gemrc
Last active December 17, 2015 18:39
gem: --no-ri --no-rdoc
# config/application.rb
module MyApp
class Application < Rails::Application
...
Time::DATE_FORMATS.merge!(:default => "%Y-%m-%d %H:%M", :ymd => "%Y-%m-%d", :md => "%m/%d", :week_day => "%u")
...
end
end
@marsz
marsz / bgstretcher.js
Created April 12, 2013 13:30
convert to utf8
/*
Background Stretcher jQuery Plugin
© 2011 ajaxBlender.com
For any questions please visit www.ajaxblender.com
or email us at support@ajaxblender.com
Version: 2.0.1
*/
;(function($){
@marsz
marsz / bitly_to_kippt.rb
Last active February 13, 2023 12:55
convert and map bit.ly's "links" + "bundle" to kippt's "clips" + "list"
# encoding: utf-8
require 'active_support/core_ext/object'
require "net/https"
require "uri"
require "kippt"
require "hashie"
# install kippt api client gems:
#
# gem install kippt
module ActsAsIsEnabled
extend ActiveSupport::Concern
module ClassMethods
def acts_as_is_enabled
scope :enabled, where(:is_enabled => true)
scope :disabled, where(:is_enabled => [false,nil]) # 如果 db 有設定 default => false 的話, 不用 nil 了, 看起來也會乾淨一點
end
end
class User
@queue = "update_status"
def self.perform(user_id,status)
User.find(user_id).update_attributes(:status=>status)
end
end
@marsz
marsz / gist:884674
Created March 24, 2011 06:51
clip + css spreties
<html>
<head>
<style type="text/css">
div {
position:relative;
top:-100px;
}
img {
position: absolute;
clip:rect(100px 100px 200px 0px);
<?php
phpinfo();
?>