Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
#
# Put me in cron.daily, cron.hourly or cron.d for your own custom schedule
# Running daily? You'll keep 3 daily backups
# Running hourly? You'll keep 3 hourly backups
NUM_BACKUPS_TO_KEEP=3
# Who wants to know when the backup failed, or
# when the binary logs didn't get applied
@caot
caot / cluster_check.sh
Last active November 29, 2017 19:20
Check on cluster jobs' status and email report Idle jobs
#!/bin/bash
NL=$'\n'
#EXP='DISK WARNING|DISK OK'
OK="DISK OK"
WARNING="DISK WARNING"
CRITICAL="DISK CRITICAL"
#!/bin/bash
# Usage: clusterctl start|stop
#
# Launches a local RabbitMQ cluster
#
# The name returned by `hostname -s` must resolve to 127.0.0.1
CLUSTER_SIZE=4
NODENAME_PREFIX='rmq'
@caot
caot / SortedArray
Last active August 29, 2015 14:02 — forked from kmdarshan/gist:6719785
Given a sorted array that has been transposed (that is, a portion has been removed from one end and attached to the other), write a function to determine if a given number is present in the array. Example: (7, 8, 9, 10, 1, 2, 3, 4, 5, 6) => find 9, 5, 11;
class SortedArray {
static boolean ispresent(int[] a, int i) {
return i == find(a, 0, a.length - 1, i);
}
static int find(int[] a, int low, int high, int i) {
int m = low + (high - low) / 2;
if (i == a[m])
@caot
caot / LCA.java
Created June 19, 2014 20:49
Tarjan's off-line lowest common ancestors algorithm in java. The example tree is build upon that from link https://en.wikipedia.org/wiki/Tree_traversal. it's worth mentioning that lot of refernces including Introduction to Algorithms stated "if v.color == BLACK" only, but it looks not sufficient. It's more sufficient that "if v.color == BLACK &&…
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class TarjanOfflineLCA {
void LCA(Node u) {
MakeSet(u);
Find(u).ancestor = u;
@caot
caot / html_table_to_excel
Created July 4, 2014 00:12
html table to excel
1. include the following two jaascript
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<script src="https://raw.githubusercontent.com/caot/battatech_excelexport/master/Scripts/jquery.battatech.excelexport.js"></script>
2. Add the folling behind the targeted table with id = "tblExport"
<script>
$(document).ready(function () {
$("#btnExport").click(function () {
@caot
caot / dataclean.tcl
Last active August 29, 2015 14:04
tcl script to parse and clean datafile. the language seems one of the worst.
#! /bin/env tclsh
proc clean {infilename outfilename} {
set delimiter "|"
set char_to_be_removed "^"
set newline "\x0d"
set infile [open $infilename r]
set outfile [open $outfilename "w"]
@caot
caot / gist:fd799856d1dba22d30db
Created July 29, 2014 19:45
Finding the kth smallest out of an unsorted array of n elements
The following Randomized solution can be found anywhere.
QuickSelect: Given array A of size n and integer k ≤ n,
1. Pick a pivot element p at random from A.
2. Split A into subarrays LESS and GREATER by comparing each element to p as in
Quicksort. While we are at it, count the number L of elements going in to LESS.
3. (a) If L = k − 1, then output p.
(b) If L > k − 1, output QuickSelect(LESS, k).
(c) If L < k − 1, output QuickSelect(GREATER, k − L − 1)
@caot
caot / byte array from or to double
Created August 16, 2014 01:35
byte array from / to double [ c++ vs java ]
c++
long result = getByte() & 0xFF;
result |= (getByte() & 0xFF) << 8;
result |= (getByte() & 0xFF) << 16;
result |= (getByte() & 0xFF) << 24;
result |= (getByte() & 0xFF) << 32;
result |= (getByte() & 0xFF) << 40;
result |= (getByte() & 0xFF) << 48;
result |= (getByte() & 0xFF) << 56;
@caot
caot / easyiosapps
Last active August 29, 2015 14:08 — forked from fbeeper/easyiosapps
#!/bin/bash
#
# Using the information available in the new iOS8 simulator for each
# device/runtime (device.plist), this script creates a readable folder structure
# (no UDIDs, just simple device/runtime names). Inside that structure it creates
# soft links to your apps in development.
#
# You can run this script every time you install an app to your simulator, or
# you can simply call it to access this folder making sure it will always be
# updated :)