Skip to content

Instantly share code, notes, and snippets.

View alexcheng1982's full-sized avatar
🎯
Focusing

Fu Cheng alexcheng1982

🎯
Focusing
View GitHub Profile
@alexcheng1982
alexcheng1982 / gson_streaming.java
Last active December 23, 2015 11:39
GSON JSON writer streaming
Object result = getResult();
if (result instanceof List) {
StringWriter output = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(output);
List list = (List) result;
jsonWriter.beginArray();
for (int i = 0, n = list.size(); i < n; i++) {
Object obj = list.get(i);
GSON.toJson(obj, obj.getClass(), jsonWriter);
}
package demo;
import org.jnetpcap.Pcap;
import org.jnetpcap.PcapIf;
import org.jnetpcap.packet.JMemoryPacket;
import org.jnetpcap.packet.JPacket;
import org.jnetpcap.protocol.JProtocol;
import org.jnetpcap.protocol.lan.Ethernet;
import org.jnetpcap.protocol.network.Ip4;
import org.jnetpcap.protocol.tcpip.Udp;
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("-", "");
}