Skip to content

Instantly share code, notes, and snippets.

View echohn's full-sized avatar

Echo echohn

View GitHub Profile
@echohn
echohn / backup_safari_bookmarks.sh
Last active December 26, 2017 09:14
safari auto backup bookmarks bash script
#!/bin/bash
usage(){
echo "USAGE: bash $0 OUTPUT_PATH"
exit 1
}
[[ $# -ne 1 ]] && usage
backup_path=$1
@echohn
echohn / ruby_convert_xml_to_yaml.rb
Created September 25, 2015 02:23
ruby convert xml to yaml
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 / Bookmarks.xslt
Last active July 22, 2016 07:18
safari auto backup bookmarks xslt file
<?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 July 18, 2016 14:56
active-record database tasks
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 April 24, 2016 14:19 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# 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")
{
"title": "Apache and Tomcat Logs",
"services": {
"query": {
"list": {
"0": {
"query": "apache !tomcat !static",
"alias": "",
"color": "#7EB26D",
"id": 0,
@echohn
echohn / getopt.sh
Created October 8, 2015 12:35
bash getopt
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
@echohn
echohn / getopts.sh
Created October 8, 2015 12:33
bash getopts
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 October 8, 2015 10:17
get dir of script(shell)
dir_of_script=$(cd "$(dirname "$0")"; pwd)
@echohn
echohn / md-menu.html
Last active September 25, 2015 02:21 — forked from cloudsben/md-menu.html
Markdown 目录生成
<link rel="stylesheet" href="http://yandex.st/highlightjs/6.2/styles/googlecode.min.css">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="http://yandex.st/highlightjs/6.2/highlight.min.js"></script>
<script>hljs.initHighlightingOnLoad();</script>
<script type="text/javascript">
$(document).ready(function(){
$("h2,h3,h4,h5,h6").each(function(i,item){
var tag = $(item).get(0).localName;