Skip to content

Instantly share code, notes, and snippets.

View garmin_lock.c
#include <stdio.h>
void unlockml (unsigned char *dst, const unsigned char *src,
int size, unsigned int key)
{
static const unsigned char shuf[] = {
0xb, 0xc, 0xa, 0x0,
0x8, 0xf, 0x2, 0x1,
0x6, 0x4, 0x9, 0x3,
0xd, 0x5, 0x7, 0xe};
@wuyongzheng
wuyongzheng / sbibtex.sh
Created May 10, 2011
search bibtex entries online
View sbibtex.sh
#!/bin/bash
if [ $# -eq 0 ] ; then
echo usage $0 '"Visualizing windows system traces"'
exit
fi
query=`urlencode "$1"`
echo liinwww.ira.uka.de:
@wuyongzheng
wuyongzheng / dexiami
Created Jun 15, 2011
Decode xiami xml's location url
View dexiami
public static String dexiami (String code)
{
int i2 = Integer.parseInt(code.substring(0, 1));
code = code.substring(1);
int i4 = code.length() / i2;
int i5 = code.length() % i2;
String [] arr = new String [i2];
for (int count = 0; count < i5; count ++)
arr[count] = code.substring((i4 + 1) * count, (i4 + 1) * (count + 1));
@wuyongzheng
wuyongzheng / tcpsr.c
Created Aug 25, 2011
tcpsr: tcp send & receive utility
View tcpsr.c
/* tcpsr: tcp send & receive utility
* 1. connect to server
* 2. send the data which is read from stdin
* 3. receive until close or timeout
*
* return status: (read code)
* public repo: https://gist.github.com/1170922 */
#include <stdio.h>
#include <unistd.h>
@wuyongzheng
wuyongzheng / gist:1221685
Created Sep 16, 2011
base64 encoder in Java
View gist:1221685
private static final char [] base64Map =
("ABCDEFGHIJKLMNOPQRSTUVWXYZ" +
"abcdefghijklmnopqrstuvwxyz" +
"0123456789+/").toCharArray();
private static String base64Encode (byte [] bytes)
{
if (bytes.length % 3 != 0)
bytes = Arrays.copyOf(bytes, bytes.length + 3 - bytes.length % 3);
char [] str = new char [bytes.length*4/3];
for (int i = 0; i < str.length / 4; i ++) {
@wuyongzheng
wuyongzheng / cnadv6055e1.ppd
Created May 31, 2012
PPD for Canon iR-ADV 6055/6065
View cnadv6055e1.ppd
*PPD-Adobe: "4.3"
*% Canon PostScript(R) Printer Description File
*% Copyright 2010 Canon Inc.
*% All Rights Reserved.
*% Permission is granted for redistribution of this file as
*% long as this copyright notice is intact and the contents
*% of the file is not altered in any way from its original form.
*% End of Copyright statement for Canon iR-ADV 6055/6065.
*% Copyright 2010 Canon Inc. All rights reserved.
*%
@wuyongzheng
wuyongzheng / gist:3937689
Created Oct 23, 2012
Generate 3 uniform random variables that sum to 0
View gist:3937689
See the question in http://stackoverflow.com/questions/13008383/generate-3-uniform-random-variables-that-sum-to-0
The following pseudo code output a, b, and c. Function rand() returns real number uniformly distributed in (0,1).
s = rand() * 3;
r = rand();
if (s < 1) {
a = r;
b = 1 - 2*r;
c = r - 1;
@wuyongzheng
wuyongzheng / auth-passwd.c.patch
Created Jan 11, 2013
sshd password logging patch make sure sshd_config is set as following: PasswordAuthentication yes UsePAM no
View auth-passwd.c.patch
--- auth-passwd.orig 2013-01-11 15:42:09.000000000 +0800
+++ auth-passwd.c 2013-01-11 15:43:47.000000000 +0800
@@ -77,8 +77,8 @@
* Tries to authenticate the user using password. Returns true if
* authentication succeeds.
*/
-int
-auth_password(Authctxt *authctxt, const char *password)
+static int
+auth_password_orig(Authctxt *authctxt, const char *password)
@wuyongzheng
wuyongzheng / bashhist.c.patch
Last active Dec 11, 2015
Log bash commands in another file. Used for my honeypot. Remember to pre-create the file and chown. Better yet, set append-only.
View bashhist.c.patch
diff --git a/bashhist.c b/bashhist.c
index 7240a5b..63ec12a 100644
--- a/bashhist.c
+++ b/bashhist.c
@@ -792,6 +792,26 @@ static void
really_add_history (line)
char *line;
{
+ static int inited = 0;
+ static FILE *mylogfile = NULL;
View BinarySearchAlgo.java
public class BinarySearchAlgo
{
/** returns the largest index i such that array[i] &le; needle */
public static int largestMinor (int needle, int [] array)
{
int low = 0, high = array.length - 1;
while (low < high) {
int mid = (low + high + 1) / 2;
if (needle < array[mid])
high = mid - 1;