Skip to content

Instantly share code, notes, and snippets.

View sontx's full-sized avatar

No Em sontx

View GitHub Profile
@sontx
sontx / demo_wait_and_notify.java
Last active March 29, 2016 15:35
A simple demo for using wait() and notify() method in java to sync thread
public class Program {
static Object lock = new Object();
static class A implements Runnable {
@Override
public void run() {
synchronized (lock) {
System.out.println("I'm running in thread A");
System.out.println("Call wait() in thread A");
@sontx
sontx / postfix_demo.java
Created March 31, 2016 14:20
A simple demo for compute a math expression by convert infix to postfix expression
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
public final class Caculator {
private static boolean isOperator(char ch) {
return ch == '+' || ch == '-' || ch == '*' || ch == '/';
}
private static int getPriority(String token) {
public static void setSystemLookAndFeel() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException
| UnsupportedLookAndFeelException e) {
}
}
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public final class WildcardMatcher {
private static final Pattern regex = Pattern.compile("[^*?]+|(\\*)|(\\?)");
private final Pattern escapeRegex;
private String getEscapeExpression(String expression) {
Matcher matcher = regex.matcher(expression);
StringBuffer buffer = new StringBuffer();
@sontx
sontx / send_key.cs
Created April 11, 2016 16:30
using keybd_event to send virtual key code
using System;
using System.Runtime.InteropServices;
[DllImport("user32.dll")]
static extern void keybd_event(byte bVk, byte bScan, uint dwFlags, uint dwExtraInfo);
void PressKey(byte keyCode)
{
const int KEYEVENTF_EXTENDEDKEY = 0x1;
const int KEYEVENTF_KEYUP = 0x2;
@sontx
sontx / preprocess_example-another.cpp
Last active May 28, 2016 09:09
Blog: Source compile process trong C++
#include "another.h"
int n){
printf("Number is %d\n", n);
}
int main(){
func(NUM);
}
@sontx
sontx / preprocess_example-another-ouput.cpp
Last active May 28, 2016 09:12
Blog: Source compile process trong C++
void func(int n){
printf("Number is %d\n", n);
}
int main(){
func(10);
}
@sontx
sontx / compile_and_link_example-another.cpp
Last active May 28, 2016 09:19
Blog: Source compile process trong C++
@sontx
sontx / html_example-simple_html.html
Last active May 28, 2016 09:23
Blog: Tổng quan về sử dụng mô hình MVC để xây dựng web động
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<h1>This is a Heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
@sontx
sontx / javascript_example-simple_javascript.js
Created May 28, 2016 09:25
Blog: Tổng quan về sử dụng mô hình MVC để xây dựng web động
function factorial(n) {
if (n == 0) {
return 1;
}
return n * factorial(n - 1);
}