Skip to content

Instantly share code, notes, and snippets.

@LCShen
LCShen / railscasts.rb
Created January 31, 2017 00:46 — forked from samqiu/railscasts.rb
Download free Railscast video
#!/usr/bin/ruby
require 'rss'
# Usage
# $ ./railscasts.rb http://railscasts.com/subscriptions/YOURRAILSCASTRSS/\/
# episodes.rss
# OR
# $ ./railscasts.rb
p 'Downloading rss index'
@LCShen
LCShen / dabblet.css
Created March 10, 2017 14:12 — forked from ryanj/dabblet.css
A Sample CSS upgrade for Eventbrite's default event pages
/**
* A Sample CSS upgrade for Eventbrite's default event pages
*/
/*-----------------------------------------------------------------
Theme: No Compromises
By: The Eventbrite Design Team
To use this theme follow these five easy steps.
1) Login to your Eventbrite account. If you don't have one visit
@LCShen
LCShen / legacy.markdown
Created March 22, 2017 15:27 — forked from jcasimir/legacy.markdown
Legacy Databases

Legacy Databases

Not every application starts from scratch, sometime you have to deal with a legacy database. Walking the Rails golden path makes life easy, and there's a perception that stepping off that path is incredibly painful.

It's not true. If your database is well designed and but doesn't follow the Rails naming conventions, it's easy to make them play nicely together. However, if your database structure is crap to begin with, then there's only so much Rails can do for you. ActiveRecord is a mapper between the database and objects, but it's not a DBA-in-a-Box.

Theory

In a green-field app, ActiveRecord and the Database fit right together:

@LCShen
LCShen / msaccess_adapter.rb
Created April 18, 2017 14:05 — forked from dcparker/msaccess_adapter.rb
msaccess_adapter.rb for an older version of ActiveRecord
require 'active_record/connection_adapters/abstract_adapter'
require 'bigdecimal'
require 'bigdecimal/util'
# msaccess_adapter.rb -- ActiveRecord adapter for Microsoft Access Db
#
# "Adapted" from the sqlserver_adapter.rb for Microsoft SQL Sever:
# Author: Joey Gibson <joey@joeygibson.com>
#
@LCShen
LCShen / mdb.rb
Created May 10, 2017 09:05 — forked from ecleel/mdb.rb
Ruby MS Access adapter
require 'rubygems'
require 'win32ole'
require 'csv'
mdb_file="c:/Sites/labs/50q.bok"
class AccessDb
attr_accessor :mdb, :connection, :data, :fields, :catalog
def initialize(mdb=nil)
@LCShen
LCShen / callbacks.rb
Created June 20, 2017 08:17
Callback logging
# With thanks to https://github.com/optoro/activerecord-callback_notification for original inspiration
if Rails.env.development?
module ActiveRecord
module CallbackNotifications
extend ActiveSupport::Concern
module ClassMethods
def notify_all_callbacks
# Make sure all models are loaded before trying to enumerate
@LCShen
LCShen / ssl.md
Created August 6, 2017 07:26
为什么不应该用 SSL 翻墙

SSL 设计目标:

  1. 防内容篡改
  2. 防冒充服务器身份
  3. 加密通信内容

而翻墙的目标:

  1. 不被检测出客户端在访问什么网站
  2. 不被检测出服务器在提供翻墙服务
@LCShen
LCShen / db.rake
Created August 14, 2017 01:15 — forked from hopsoft/db.rake
Rails rake tasks for dump & restore of PostgreSQL databases
# lib/tasks/db.rake
namespace :db do
desc "Dumps the database to db/APP_NAME.dump"
task :dump => :environment do
cmd = nil
with_config do |app, host, db, user|
cmd = "pg_dump --host #{host} --username #{user} --verbose --clean --no-owner --no-acl --format=c #{db} > #{Rails.root}/db/#{app}.dump"
end
puts cmd
@LCShen
LCShen / old_file_killer.rb
Created January 6, 2018 10:44 — forked from pelgrim/old_file_killer.rb
A Ruby script to delete files older than X days in a given directory.
#!/usr/bin/env ruby
# A Ruby script to delete files older than X days in a given directory. Pretty simple.
# Like this: file_control.rb /User/pelgrim/Documents '*.pdf' 7
# The command above you remove ALL your pdfs inside Documents older than SEVEN DAYS.
# Quickly written by pelgrim < guskald at gmail dot com >
unless ARGV.size == 3
puts "Usage: file_control <directory> <filename pattern> <max age>"
exit 1
@LCShen
LCShen / document.xml
Created April 21, 2018 16:44 — forked from spiffistan/document.xml
repaired docx
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:wpc="http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas" xmlns:mo="http://schemas.microsoft.com/office/mac/office/2008/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp14="http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:w14="http://schemas.microsoft.com/office/word/2010/wordml" xmlns:w15="http://schemas.microsoft.com/office/word/2012/wordml" xmlns:wpg="http://schemas.microsoft.com/of