Skip to content

Instantly share code, notes, and snippets.

View zxteloiv's full-sized avatar

Haruki Kirigaya zxteloiv

View GitHub Profile
@zxteloiv
zxteloiv / door.lst
Last active January 23, 2016 08:22
Shell scripts to securely log in to remote machine from a shared machine.Users can use `ps aux` to see what others are doing. So if you set password to perform auto-login in command arguments, that password will be easily seen by others.expect script can read from file, that means if you stores password in a file, `ps aux` will not expose your p…
# password file that stores user name and password
sessionid 192.168.1.15 user123 pass123
@zxteloiv
zxteloiv / lcs.php
Last active December 11, 2015 15:29
longest common substring in php, note it's different from longest common subsequence
#!/usr/local/php/bin/php
<?php
function get_longest_common_substring($string_1, $string_2) {
$string_1_length = strlen($string_1);
$string_2_length = strlen($string_2);
$return = "";
if ($string_1_length === 0 || $string_2_length === 0) {
// No similarities
@zxteloiv
zxteloiv / reverse.php
Created February 28, 2013 13:56
reverse Chinese characters per line
#!/usr/local/php/bin/php
<?php
function cstrrev($str)
{
$len = strlen($str);
for($i = 0; $i < $len; $i++)
{
$char = $str{0};
if(ord($char) > 127)
@zxteloiv
zxteloiv / rand.py
Last active December 14, 2015 08:19
sampling data simple random or qv-random
#!/usr/local/bin/python
import sys
import random
def GetRand(src, N, dest):
query_list = []
# load src query
fp = open(src, "r")
@zxteloiv
zxteloiv / db_handle.py
Created February 28, 2013 14:04
python db operations example
#coding=gbk
import time
import MySQLdb
import sys
class DbHandle:
def __init__(self, host_name, usr_name, usr_password, data_base, charset = 'gbk'):
self.m_host_name = host_name
self.m_usr_name = usr_name
self.m_usr_password = usr_password
@zxteloiv
zxteloiv / sendmail.pl
Last active December 14, 2015 08:18
sending mail using perl, with auth
#!/usr/bin/perl
use Net::SMTP;
use Authen::SASL;
if(@ARGV < 2){
die "usage: SendMail.pl <MailTo> <MimeFile>";
}
my($MailTo, $MimeFile) = @ARGV;
my $smtp = Net::SMTP->new('111.222.3.123');
@zxteloiv
zxteloiv / get_length.py
Last active January 2, 2016 11:55
get the amount of Chinese character in a string
import sys
# Use the property:
# Almost every Chinese character is 3 bytes in UTF-8
"""
# bytes length check
for line in open(sys.argv[1], "r"):
parts = line.rstrip('\r\n').split('\t')
if len(parts[0].strip()) <= 3:
@zxteloiv
zxteloiv / fix-right-alt.reg
Created February 28, 2013 14:39
fix right alt to the same as left alt, under putty
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
"Scancode Map"=hex:00,00,00,00,00,00,00,00,02,00,00,00,38,00,38,e0,00,00,00,00
@zxteloiv
zxteloiv / mylist.hpp
Last active December 18, 2015 12:29
An C++ implementation of linked list resembling STL list
///////////////////////////////////////////////////////////////
// Filename : MyList.h
// Author : Zhang Xiang
// Date : 2010-8-18
// Comment : A two-direction list class and it implemented part of the
// functions as the list container of STL come with Visual
// studio.
//
// Iterator class name is MyListIterator, and the value is a
// four-byte integer, which may need a type cast in the pointer
@zxteloiv
zxteloiv / testlogging.py
Created December 8, 2014 18:27
logging tutorial
# coding: utf-8
import sys, logging, logging.handlers, time, multiprocessing
def setLogger(name):
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
handler = logging.handlers.WatchedFileHandler('info.log')
formatter = logging.Formatter('%(asctime)s\t%(message)s')
handler.setFormatter(formatter)