Skip to content

Instantly share code, notes, and snippets.

@hydra1983
hydra1983 / ssh-tunnel
Last active May 2, 2018 09:26
script to start a ssh tunnel using autossh on ubuntu
#! /bin/sh
#
# Author: Edison <hydra1983@gmail.com>
#
# This is a modified version for from Andreas Olsson <andreas@arrakis.se>
# For each tunnel; make a uniquely named copy of this template.
## SETTINGS
#
# autossh monitoring port (unique)
@hydra1983
hydra1983 / geminabox
Created November 15, 2012 08:27
geminabox startup scripts
#!/bin/bash
### BEGIN INIT INFO
# Provides: geminabox
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start Geminabox.
# Description: Start the Geminabox service.
@hydra1983
hydra1983 / vpn init script
Created January 7, 2013 10:47
init script to connect or disconnect vpn client
#!/bin/sh
### BEGIN INIT INFO
# Provides: vpn
# Required-Start: $syslog $local_fs $remote_fs $network $named
# Required-Stop: $syslog $local_fs $remote_fs $network $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start the vpn.
### END INIT INFO
@hydra1983
hydra1983 / ant-contrib_for_i
Last active December 18, 2015 17:49
Counter for iteration a list in for task based on math task of ant-contrib
<var name="counter" value="0"/>
<for list="{list}" param="{param}">
<sequential>
<switch value="${counter}">
<case value="0">
<!-- do something -->
</case>
<case value="1">
<!-- do something -->
@hydra1983
hydra1983 / progress-generator
Created August 7, 2013 06:53
An algorithm to generate progress info for tasks. Run with nodejs.
var num = 0;
var num2 = 0.0;
var num3 = 0.0;
var num4 = 0.0;
var num5 = 0.0;
console.log("part1");
var part1 = [{
batchCount : 5
},{
@hydra1983
hydra1983 / wildcard_matcher.java
Last active May 27, 2021 08:24
Convert wildcard pattern to regular expression to match strings
public class Main {
public static void main(String[] args) {
test("<html*", "<html></html>");
test("12*?", "12345");
test("12*4?", "12345");
}
private static void test(String pattern, String input) {
Pattern p = Pattern.compile(pattern);
System.out.println(pattern + " : " + input + " matches? "
@hydra1983
hydra1983 / LongestCommonSequence.java
Created November 17, 2013 10:10
Longest Common Sequence
public class LongestCommonSequence {
public static void main(String[] args) {
String str1 = "ABCBDAB";
String str2 = "BDCABA";
String lcs = lcs(str1, str2);
System.out.println(lcs);
System.out.println(lcs.length());
}
@hydra1983
hydra1983 / LongestCommonSubstring.java
Created November 18, 2013 06:27
Longest Common Substring
public class LongestCommonSubstring {
public static void main(String[] args) {
String str1 = "21232523311324";
String str2 = "312123223445";
String lcs = lcs(str1, str2);
System.out.println(lcs);
System.out.println(lcs.length());
}
@hydra1983
hydra1983 / JaroWinklerDistance.java
Last active December 28, 2015 15:39
Jaro-Winkler Distance
public class JaroWinklerDistance {
public static void main(String[] args) {
String s1 = "MARTHA";
String s2 = "MARHTA";
// String s1 = "MARTHA";
// String s2 = "MARHTA";
// int range = Math.floor(Math.max(s1.length(),s2.length())/2) - 1 = 2;
// int isMatched = (s1.charAt(row) == s2.charAt(col) && Math.abs(row - col) <= range) ? 0 : 1;
// 0 1 2 3 4 5 t
// M A R H T A
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
height="100"
width="100">
<fx:Declarations>
<s:ArrayCollection id="damages">
<fx:Array>
<fx:Object damage="damage1"