Skip to content

Instantly share code, notes, and snippets.

View alexcheng1982's full-sized avatar
๐ŸŽ‰
AI time

Fu Cheng alexcheng1982

๐ŸŽ‰
AI time
View GitHub Profile
angular.module('controllers', ['services'])
.controller('MyCtrl', ['$scope', ($scope) ->
$scope.$watch('dataReady', (ready) ->
init() if ready
)
init = () ->
console.log('Init')
])
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?
#!/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'])
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]
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;
@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);
}