Skip to content

Instantly share code, notes, and snippets.

Avatar

Echo echohn

View GitHub Profile
@echohn
echohn / backup_safari_bookmarks.sh
Last active Dec 26, 2017
safari auto backup bookmarks bash script
View backup_safari_bookmarks.sh
#!/bin/bash
usage(){
echo "USAGE: bash $0 OUTPUT_PATH"
exit 1
}
[[ $# -ne 1 ]] && usage
backup_path=$1
@echohn
echohn / Bookmarks.xslt
Last active Jul 22, 2016
safari auto backup bookmarks xslt file
View Bookmarks.xslt
<?xml version='1.0' encoding='UTF-8'?>
<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>
<xsl:output method='html' version='1.0' encoding='UTF-8' indent='yes'/>
<xsl:template match="plist">
@echohn
echohn / Rakefile
Last active Jul 18, 2016
active-record database tasks
View Rakefile
namespace :db do
desc "Migrate the db"
task :migrate do
connection_details = YAML::load(File.open('config/database.yml'))
ActiveRecord::Base.establish_connection(connection_details)
ActiveRecord::Migrator.migrate("db/migrate/")
end
desc "Create the db"
@echohn
echohn / rspec-syntax-cheat-sheet.rb
Created Apr 24, 2016 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
View rspec-syntax-cheat-sheet.rb
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
View apache-and-tomcat-logs.json
{
"title": "Apache and Tomcat Logs",
"services": {
"query": {
"list": {
"0": {
"query": "apache !tomcat !static",
"alias": "",
"color": "#7EB26D",
"id": 0,
View getopt.sh
ARGS=`getopt -o dph -l help,debug,jdk-update,jdk-retreat,tomcat-update,tomcat-retreat,apache-update,apache-retreat,tomcat-conn-update -- "$@"`
[ $? -ne 0 ] && usage
eval set -- ${ARGS}
while [ true ]
do
case $1 in
--debug)
IS_DEBUG="true"
debug=1
View getopts.sh
while getopts "abc:def:ghi" OPT
do
echo "$OPT" $OPTIND $OPTARG # 这里$OPTIND 是一个索引序列号,$OPTARG 是选项里所记录的值,无值是为空,默认情况下选项是以空格分隔
case $OPT in
a) aflag=1
;;
b) bflag=1
;;
c) cflag=1
clist=$OPTARG
@echohn
echohn / git_dir_of_script.sh
Created Oct 8, 2015
get dir of script(shell)
View git_dir_of_script.sh
dir_of_script=$(cd "$(dirname "$0")"; pwd)
@echohn
echohn / ruby_convert_xml_to_yaml.rb
Created Sep 25, 2015
ruby convert xml to yaml
View ruby_convert_xml_to_yaml.rb
require 'active_support/core_ext/hash/conversions'
require 'yaml'
file = File.open("data/mconvert.xml", "r")
hash = Hash.from_xml(file.read)
yaml = hash.to_yaml
File.open("data/mirador.yml", "w") { |file| file.write(yaml) }
@echohn
echohn / gist:c439b503733eea60a45b
Created Jul 17, 2015
批量修改 git 提交的用户信息
View gist:c439b503733eea60a45b
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="old@email.com"
CORRECT_NAME="echo"
CORRECT_EMAIL="new@email.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
You can’t perform that action at this time.