Skip to content

Instantly share code, notes, and snippets.

View jongha's full-sized avatar

Jong-Ha Ahn jongha

View GitHub Profile
@jongha
jongha / mongo-parse.js
Created March 27, 2015 02:37
URL query string parameter to mongoose parameters
exports.query = function(query) {
var operator = {};
if (query) {
var tokenize = function(operator, str) {
var data = str.split(operator);
if (data.length > 1) {
return data;
}
return null;
@jongha
jongha / Gruntfile.js
Created March 27, 2015 02:48
My Gruntfile.js sample
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
clean: ['static/assets/user/bare'],
jshint: {
files: ['Gruntfile.js', 'static/assets/user/js/**/*.js'],
options: {
globals: {
@jongha
jongha / gist:7d549fbcf385dedcc582
Last active August 29, 2015 14:19
GetListItems using Func Generic in C#
Func<List<int>, ListItem[]> GetListItems = (items) =>
{
List<ListItem> list = new List<ListItem>();
foreach(int i in items)
{
string item = i.ToString("D2");
list.Add(new ListItem()
{
Text = item,
Value = item
@jongha
jongha / Swap.cs
Created April 22, 2015 05:49
Swap using XOR algorithm in C#
// http://en.wikipedia.org/wiki/XOR_swap_algorithm
private void Swap(ref int x, ref int y)
{
x ^= y;
y ^= x;
x ^= y;
}
@jongha
jongha / gist:d5c557096b67f79db44b
Created April 24, 2015 07:58
Sync system time in Linux using crontab
30 1 * * * root /usr/bin/rdate -s time.bora.net && /sbin/clock -w
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import smtplib
import datetime
from optparse import OptionParser
from smtplib import SMTP as SMTP
#!/bin/sh
REPOS="$1"
REV="$2"
#mailer.py commit "$REPOS" "$REV" /path/to/mailer.conf
MESSAGE=$(svnlook propget --revprop -r $REV $REPOS svn:log)
cat <<EOF | /root/monitor/sendmail.py -s "[COMMIT] $REPOS:$REV" -r user@domain
REPOS: $REPOS
public class Palindrome {
public static void main(String[] args) {
System.out.println(isPalindrome("amor roma"));
System.out.println(isPalindrome("Was it a car or a cat I saw?"));
}
public static Boolean isPalindrome(String text) {
StringBuilder builder = new StringBuilder();
for (char c : text.toCharArray()) {
@jongha
jongha / IsSorted.java
Last active August 29, 2015 14:22
#java #sort #algorithm
public class IsSorted {
public static void main(String[] args) {
System.out.println(isSorted(new int[] { 1, 2, 3, 4 })); // true
System.out.println(isSorted(new int[] { 1, 2, 3, 0 })); // false
}
public static boolean isSorted(int[] items) {
for (int i = 0; i < items.length - 1; ++i) {
if (items[i] > items[i + 1]) {
@jongha
jongha / SoundexClass.java
Last active August 29, 2015 14:22
Soundex Algorithm
// reference: http://en.wikipedia.org/wiki/Soundex
public class SoundexUtil {
// public static void main(String[] args) {
// System.out.println(soundex("Gauss")); // G200
// System.out.println(soundex("AHN")); // A500
// }
public static String soundex(String text) {
StringBuilder builder = new StringBuilder();