Skip to content

Instantly share code, notes, and snippets.

View trung's full-sized avatar
🏕️
...

⚆ Trung Nguyen trung

🏕️
...
View GitHub Profile
-record(abstract_message, {
clientId,
destination,
messageId,
timestamp,
timeToLive,
headers,
body
}).
-record(async_message, {
%% For each header file, it scans thru all records and create helper functions
%% Helper functions are:
%% setters, getters, fields, fields_atom, type
-module(record_helper).
-export([make/1, make/2]).
make(HeaderFiles) ->
make([ atom_to_list(X) || X <- HeaderFiles ], ".").
%% This is auto generated file. Please don't edit it
-module(record_utils).
-compile(export_all).
-include("messages.hrl").
fields(abstract_message) ->
["clientId", "destination", "messageId", "timestamp", "timeToLive", "headers", "body"];
fields(async_message) ->
%% To demonstrate tail recursion in Erlang
-module (tailrecursion).
-export ([fact/1, qsort/1, loop/0]).
%% Factorial
fact(N) -> fact(N, 1).
fact(0, A) -> 1*A;
fact(N, A) -> fact(N-1, N*A).
% Quick sort
-module (recursion).
-export ([qsort/1]).
qsort([]) -> [];
qsort([Pivot|T]) ->
qsort([X || X <- T, X < Pivot])
++ [Pivot] ++
qsort([X || X <- T, X >= Pivot]).
@trung
trung / unicode_to_dncr.pl
Created November 7, 2010 06:49
Convert Unicode to Decimal NCR
use strict;
use utf8;
# convert unicode to Decimal NCR format
sub convertUnicodeToDecimalNCR {
my ($self, $str) = @_;
# important
utf8::decode($str);
my $ret_str = "";
while ($str =~ /(.)/g) {
@trung
trung / Attachment.java
Created December 3, 2010 01:55
How to build/read attachment part using JavaMail in GAE
class Attachment {
public byte[] data;
public String fileName;
public String contentType;
public Attachment(String fileName, byte[] data, String contentType) {
this.data = data;
this.fileName = fileName;
int id = contentType.indexOf(";");
this.contentType = id > -1 ? contentType.substring(0, id) : contentType;;
@trung
trung / RemoveHandler.java
Created March 18, 2011 01:12
snippet shows how to remove handler registration within anonymous handler
// http://stackoverflow.com/questions/4715034/gwt-problem-with-handlerregistration/5275448#5275448
final Set<HandlerRegistration> hack = new HashSet<HandlerRegistration>();
((FocusWidget) sourceWidget).setFocus(true);
hack.add(((FocusWidget) sourceWidget).addBlurHandler(new BlurHandler() {
@Override
public void onBlur(BlurEvent event) {
ApplicationUtils.getTipsy().hide();
for (HandlerRegistration hr : hack) {
@trung
trung / JarReader.java
Last active January 2, 2024 14:33
Reading files from Jar file recursively
package xyz.com;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
@trung
trung / aws_default_route_table.tf
Last active July 14, 2017 15:12
How to retrieve default route table id for a VPC
variable "vpcId" {
default = "vpc-5f98eb36"
}
data "aws_route_table" "all" {
vpc_id = "${var.vpcId}"
filter {
name = "association.main"
values = ["true"]
}