Skip to content

Instantly share code, notes, and snippets.

View marshluca's full-sized avatar
🏠
Working from home

Lucas Zhang marshluca

🏠
Working from home
View GitHub Profile
@marshluca
marshluca / MongoDB.sh
Created August 13, 2010 04:09
MongoDB init script
#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
#!/usr/bin/env ruby -wKU
require "net/http"
require "uri"
####################### Standard HTTP Request #######################
def standard_http_request
uri = URI.parse("http://wwwgoogle.com.hk")
# Shortcut
@marshluca
marshluca / caches_action.rb
Created August 26, 2011 07:01
Rails Action Cache
class ListsController < ApplicationController
before_filter :authenticate, :except => :public
caches_page :public
caches_action :index, :if => proc do
!request.format.json? # cache if is not a JSON request
end
caches_action :show, :cache_path => { :project => 1 },
@marshluca
marshluca / douban_oauth.rb
Created December 10, 2010 10:21
豆瓣OAuth认证
# Douban OAuth认证包括以下四步内容
# 1. 获取Request Token
# 2. 用户确认授权
# 3. 换取Access Token
# 4. 访问受限资源
require "rubygems"
gem 'oauth','0.4.3'
require 'oauth'
# using rvm with ruby-1.8.7-p249
# latest version 2.7.7 2010-06-17
brew install libxml2
brew link libxml2
# latest version 1.13.1
brew install libiconv
brew link libiconv
@marshluca
marshluca / after.html
Created August 26, 2011 10:26
Rails 3 PipeAssets
cache: [GET /intro] miss
Started GET "/intro" for 127.0.0.1 at Fri Aug 26 18:25:29 +0800 2011
Processing by HomeController#intro as HTML
==> Got Account:5343 from cache. (0.00065)
Rendered home/intro.html.erb within layouts/application (0.1ms)
Completed 200 OK in 233ms (Views: 4.1ms | ActiveRecord: 10.7ms | Mongo: 0.0ms | Sphinx: 0.0ms | Memcache: 0.0ms)
cache: [GET /assets/application-e808531739fb5e75ea9161663d738563.css] fresh
cache: [GET /assets/index-d16c1771b786ce3dc9730baa43e2fe87.css] fresh
@marshluca
marshluca / compress_and_decompress.txt
Created February 16, 2011 10:01
linux各种解压缩命令
.gz
解压1:gunzip FileName.gz
解压2:gzip -d FileName.gz
压缩:gzip FileName
.tar.gz
解压:tar zxvf FileName.tar.gz
压缩:tar zcvf FileName.tar.gz DirName
---------------------------------------------
.bz2
@marshluca
marshluca / 107_js.txt
Created February 16, 2011 10:07
107条javascript常用小技巧
1.document.write(""); 输出语句
2.JS中的注释为//
3.传统的HTML文档顺序是:document->html->(head,body)
4.一个浏览器窗口中的DOM顺序是:window->(navigator,screen,history,location,document)
5.得到表单中元素的名称和值:document.getElementById("表单中元素的ID号").name(或value)
6.一个小写转大写的JS: document.getElementById("output").value = document.getElementById("input").value.toUpperCase();
7.JS中的值类型:String,Number,Boolean,Null,Object,Function
8.JS中的字符型转换成数值型:parseInt(),parseFloat()
9.JS中的数字转换成字符型:(""+变量)
10.JS中的取字符串长度是:(length)
@marshluca
marshluca / douban_comment.rb
Created February 16, 2011 07:35
豆瓣自动顶贴
require 'rubygems'
require 'mechanize'
def comment_douban_topic(url,text)
login_url = "http://www.douban.com/login"
agent = Mechanize.new
# agent.set_proxy("218.201.21.176","80")
agent.user_agent_alias = "Googlebot"
page = agent.get(login_url)
@marshluca
marshluca / gist:376f2787e89fb456bdc8
Created February 5, 2016 03:36
ethereum mining
☁ ~ geth --identity "LocalMiner" --genesis $chaindir/CustomGenesis.json --rpc --rpcport "8545" --rpccorsdomain "*" --datadir "$chaindir/01" --port "30303" --nodiscover --ipcapi "admin,db,eth,debug,miner,net,shh,txpool,personal,web3" --rpcapi "db,eth,net,web3" --autodag --networkid 1467510308 --nat "any" --mine --minerthreads "1"
I0205 11:27:01.206871 19343 database.go:71] Alloted 16MB cache to /Users/lucas/.eth/ebchain/01/chaindata
I0205 11:27:01.210302 19343 database.go:71] Alloted 16MB cache to /Users/lucas/.eth/ebchain/01/dapp
I0205 11:27:01.214214 19343 backend.go:314] Protocol Versions: [63 62 61], Network Id: 1467510308
I0205 11:27:01.214616 19343 genesis.go:89] Genesis block already in chain. Writing canonical number
I0205 11:27:01.214640 19343 backend.go:326] Successfully wrote genesis block. New genesis hash = 27a213a028c685b8017e6b10a30a18008d238857f6f48deee9406d9c4d40d4ac
I0205 11:27:01.214662 19343 backend.go:362] Blockchain DB Version: 3
I0205 11:27:01.215146 19343 blockchain.go:2