Skip to content

Instantly share code, notes, and snippets.

View cisolarix's full-sized avatar
🌻
Cool

Yanming Deng cisolarix

🌻
Cool
View GitHub Profile
@cisolarix
cisolarix / seeds.rb
Last active August 29, 2015 14:17 — forked from seyhunak/seeds.rb
unless Rails.env.production?
connection = ActiveRecord::Base.connection
connection.tables.each do |table|
connection.execute("TRUNCATE #{table}") unless table == "schema_migrations"
end
sql = File.read('db/import.sql')
statements = sql.split(/;$/)
statements.pop
@cisolarix
cisolarix / permission_actions.rb
Last active August 29, 2015 14:17
获取 permission actions 列表
controllers = Dir.new("#{Rails.root}/app/controllers/admin").entries
controllers.each do |controller|
if controller =~ /_controller/
cont = controller.camelize.gsub(".rb","")
cont1 = controller.gsub("_controller.rb", "")
(eval("Admin::#{cont}.action_methods")).sort.each {|met|
puts "admin/#{cont1}##{met}"
}
end
end
@cisolarix
cisolarix / 2015 年读的书.md
Last active August 29, 2015 14:14
2015 年读的书

Transactions

As your business logic gets complex you may need to implement transactions. The classic example is a bank funds transfer from account A to account B. If the withdrawal from account A fails then the deposit to account B should either never take place or be rolled back.

Basics

All the complexity is handled by ActiveRecord::Transactions. Any model class or instance has a method named .transaction. When called and passed a block, that block will be executed inside a database transaction. If there's an exception raised, the transaction will automatically be rolled back.

Example

@cisolarix
cisolarix / 常用软件推荐.md
Last active August 29, 2015 14:13
常用软件推荐

1. 付费软件篇 (Mac OS)

1.1 效率工具类

评分 名称 功能简述 单价 测评
★★★★ [Alfred] Top#1,不解释 £17 #
★★★★ [Moom] 窗口管理,多屏切换工具 $10 #
★★★☆ [CleanMyMac] 清理优化,正如其名 $39.95 #
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
#!/usr/bin/env ruby
#
# Mac fix 1 - Install the Nokogiri gem on Mac OS 10.9 Mavericks
#
# Usage: to configure and install using Bundler, pass in 'bundle' as an argument to the script.
#
# Nokogiri works at a very low level, so it has many issues on various platforms.
# As a result, the command `install gem nokogiri` often will fail. This fix is for
# errors involving 'libiconv', such as the following one I encountered:
#
@cisolarix
cisolarix / Tower 每月消息
Created November 21, 2014 07:41
Tower 每月消息
<div><br></div><div><div><br></div><div><br></div><div style="font-size: 12px;font-family: Arial Narrow;padding:2px 0 2px 0;">------------------&nbsp;原始邮件&nbsp;------------------</div><div style="font-size: 12px;background:#efefef;padding:8px;"><div><b>发件人:</b>&nbsp;"newsletter";&lt;newsletter@mailer.tower.im&gt;;</div><div><b>发送时间:</b>&nbsp;2013年9月17日(星期二) 中午12:13</div><div><b>收件人:</b>&nbsp;"yuyou"&lt;153958434@qq.com&gt;; <wbr></div><div></div><div><b>主题:</b>&nbsp;Tower每月消息(2013年09月17日)</div></div><div><br></div>
<div style="background:#EDEDED url('http://towerfiles.oss.aliyuncs.com/newsletter_static/header_bg_01-0913.jpg') 50% 12px no-repeat; min-width:700px; padding:50px 30px 30px; margin:0; font-size:16px; line-height:1.6;">
<div class="twr-newsletter-content" style="
background:#fff;
border:1px solid #ccc;
border-top:0;
max-width:700px; min-width:700px;
margin:0 auto;
padding:0
">
@cisolarix
cisolarix / tower 邮件原文
Created November 21, 2014 07:33
tower 邮件原文
Received: from mail19.sendcloud.org (unknown [101.227.180.11])
by newmx103.qq.com (NewMx) with SMTP id
for <153958434@qq.com>; Fri, 21 Nov 2014 14:12:14 +0800
X-QQ-FEAT: I0VBZjNhVPoB2VizW1VKNfwzEHh/wk1Ayezm8NFRuYe/CY1W8gkg4x8s+i55b
nocWIabTicaMC693fjWaHJsjx2PhOWvPVl+qqsxSYkN+3exA5S02EGDh8LQkP+y/Zcexwm4
kxbzFLCau0QyJCXXYsSJ4cNQ7sZW/CT3ojqQPwJseVbn+C0YPiPJ3EnTxLGtTo6RM/IeUnb
7E/yZpXNCf7WDmysWeYq1P0JU7Bnz9zA=
X-QQ-MAILINFO: MjJD59SVx+LnP5qnRvn6Mb+6nxfomRRgidftc9HxYO7Httn7xWurqKbpO
@cisolarix
cisolarix / Sublime Text related config
Created October 26, 2014 01:39
Sublime Text related config