Skip to content

Instantly share code, notes, and snippets.

View hlxwell's full-sized avatar
⛷️
Focusing

Michael He hlxwell

⛷️
Focusing
View GitHub Profile
@hlxwell
hlxwell / mail.rb
Last active August 30, 2015 10:24
ruby sending mail
def send_email(to, subject, body)
puts "sending email => #{subject}"
IO.popen(CONFIG[:sendmail_command],"w+") do |sm|
message =
%Q{Date: #{Time.now}
From: House Notify <notify@joblet.jp>
To: #{to}
Subject: #{subject}
Mime-Version: 1.0
module Contactable
def self.append_features(klass)
super
klass.extend(Macros)
end
def Macros
def acts_as_contactable
extend ClassMethods
include InstanceMethods
@hlxwell
hlxwell / cocos2d.m
Last active September 27, 2015 02:58
animation from cocos2d to UIView
-(void)openHighScoreView {
GameOverView *tempView = [[HighScoreView alloc] init];
selfish = tempView;
[tempView release];
[[CCDirector sharedDirector]replaceScene:[MainScene node]];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:.5];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:[[CCDirector sharedDirector] openGLView] cache:YES];
[[[CCDirector sharedDirector] openGLView] addSubview:go.view];
@hlxwell
hlxwell / SimpleScoredHistoriesController.rb
Created December 15, 2011 02:02
Add custom action to Qor admin.
require 'qor/resources_engine'
module Admin
class RepOps::SimpleScoredHistoriesController < Admin::ResourcesController
prepend_before_filter :pamper_resources_engine
layout 'resources/tis'
def show_history
@retailer = Retailer.find(params[:retailer_id])
@simple_scored_history = @retailer.simple_scored_history_to_be_displayed(params[:simple_scored_history_id])
@hlxwell
hlxwell / missing_template_fix.rb
Created December 24, 2011 09:43
Patch to fix MissingTemplate issue in Rails 3
module ActionController
module ImplicitRender
def default_render
# lookup template exist? go to render it
render and return if template_exists?(action_name.to_s, _prefix)
has_template = begin
old_formats, @lookup_context.formats = @lookup_context.formats, Mime::SET.symbols
template_exists?(action_name.to_s, _prefix)
@hlxwell
hlxwell / missing_template.rb
Created January 30, 2012 07:31
Missing template bug fix
module ActionController
module ImplicitRender
def send_action(method, *args)
ret = super
unless response_body
if template_exists?(action_name.to_s, _prefixes)
default_render
else
process_not_found_template
@hlxwell
hlxwell / csv_comparer.rb
Created March 16, 2012 04:11
CSV Comparer
require 'rubygems'
require 'csv'
def normalize(row)
row[2].sub!(/^0+/, "") if row[2]
row[3].sub!(/^0+/, "") if row[3]
return row
end
@hlxwell
hlxwell / mysql-to-mongo
Last active October 4, 2015 14:27 — forked from shenzhaoyan/gist:824583
MySQL to MongoDB
MySQL: SELECT * FROM user WHERE name = "foobar"Mongo: db.user.find({"name" : "foobar"})
MySQL: INSERT INOT user (`name`, `age`) values ("foobar",25)
Mongo: db.user.insert({"name" : "foobar", "age" : 25})
MySQL: DELETE * FROM user
Mongo: db.user.remove({})
MySQL: DELETE FROM user WHERE age < 30
Mongo: db.user.remove({"age" : {$lt : 30}}) $gt : > ; $gte : >= ; $lt : < ; $lte : <= ; $ne : !=
MySQL: UPDATE user SET `age` = 36 WHERE `name` = "foobar"
Mongo: db.user.update({"name" : "foobar"}, {$set : {"age" : 36}})
MySQL: UPDATE user SET `age` = `age` + 3 WHERE `name` = "foobar"
@hlxwell
hlxwell / token.rb
Created August 28, 2012 16:26
token code
require "digest"
@json_data = '{"device_id":"3079c62cc69de1eace695459207e41d71f4a53f3","logs":[{"kid_name":"Raspu","option_id":"あか","book_id":"50041a0b9a208511cd000004","question_id":"5020b1c99a208574b0000013"},{"kid_name":"Raspu","option_id":"き","book_id":"50041a0b9a208511cd000004","question_id":"5020b81c9a208574b000001f"}]}'
@correct_token = Digest::SHA2.new << "#{@json_data}3079c62cc69de1eace695459207e41d71f4a53f3"
puts @correct_token
@hlxwell
hlxwell / get_ios_app_version
Created March 22, 2013 03:09
Get iOS or Mac application version.
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];