Skip to content

Instantly share code, notes, and snippets.

View alexcheng1982's full-sized avatar
🎯
Focusing

Fu Cheng alexcheng1982

🎯
Focusing
View GitHub Profile
require 'savon'
categories = []
def process(categories, category)
categories << {:id => get_category_value(category, 'category_id'),
:name => get_category_value(category, 'name')}
children = get_category_value(category, 'children')
return if children.nil? or children[:item].nil?
childrenItem = children[:item]
#!/usr/bin/env ruby
require 'optparse'
require 'fssm'
require 'rbconfig'
THIS_FILE = File.expand_path(__FILE__)
RUBY = File.join(RbConfig::CONFIG['bindir'], RbConfig::CONFIG['ruby_install_name'])
module SampleApp
class ActivePageTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@text = text
end
def render(context)
name = context.environments.first["page"]["name"]
return '' if name.nil? or @text.nil?
angular.module('controllers', ['services'])
.controller('MyCtrl', ['$scope', ($scope) ->
$scope.$watch('dataReady', (ready) ->
init() if ready
)
init = () ->
console.log('Init')
])
@alexcheng1982
alexcheng1982 / local2rds.bash
Last active August 29, 2015 14:13
Importing Data from a MySQL DB to an Amazon RDS MySQL DB Instance
sudo mysqldump --databases world --single-transaction --compress --order-by-primary –u <local_user> -p<local_password>
| mysql --host hostname –-port 3306 –u <RDS_user_name> –p<RDS_password>
@alexcheng1982
alexcheng1982 / wrapperAngularElement.js
Last active August 29, 2015 14:14
Wrap angular element using jQuery
$(element[0]).find('input[type=text]');
@alexcheng1982
alexcheng1982 / flushCache.txt
Created January 27, 2015 20:45
Flush Linux system memory cache
free -m && sync && echo 3 > /proc/sys/vm/drop_caches && free -m
Flush daily using crontab:
0 0 * * * sudo free -m && sync && echo 3 > /proc/sys/vm/drop_caches && free -m
@alexcheng1982
alexcheng1982 / random.java
Last active August 29, 2015 14:21
Generate random string
public String getRandomString(String prefix) {
return prefix + "_" + UUID.randomUUID().toString().replaceAll("-", "");
}
@alexcheng1982
alexcheng1982 / createIndex.java
Created June 25, 2015 23:25
Elasticsearch - Create index when not exist
private void createIndex() {
boolean indexExists = client.admin().indices().prepareExists(INDEX_NAME).execute().actionGet().isExists();
if (!indexExists) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Index {} doesn't exist, create it now.", INDEX_NAME);
}
client.admin().indices().prepareCreate(INDEX_NAME).execute();
}
}
@alexcheng1982
alexcheng1982 / wechat_font.css
Created July 2, 2015 02:11
WeChat web font
body {
font-family: "Helvetica Neue",Helvetica,"Hiragino Sans GB","Microsoft YaHei","微软雅黑",Arial,sans-serif;
}