Skip to content

Instantly share code, notes, and snippets.

View zhmz1326's full-sized avatar
🤠
look ahead

Zheng Mingzhi (AI码士) zhmz1326

🤠
look ahead
View GitHub Profile
@zhmz1326
zhmz1326 / RSATest.java
Created April 14, 2017 06:59
Show how to create a BCRSAPrivateCrtKey instance by Java Reflect API
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.math.BigInteger;
import org.bouncycastle.crypto.DataLengthException;
import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;
import org.bouncycastle.jcajce.provider.asymmetric.rsa.BCRSAPrivateCrtKey;
public class RSATest {
@zhmz1326
zhmz1326 / compress.java
Created March 29, 2017 09:44
Compress a directory to a zip stream using commons-compress and java
public static void compressZipfile(String sourceDir, OutputStream os) throws IOException {
ZipOutputStream zos = new ZipOutputStream(os);
compressDirectoryToZipfile(sourceDir, sourceDir, zos);
IOUtils.closeQuietly(zos);
}
private static void compressDirectoryToZipfile(String rootDir, String sourceDir, ZipOutputStream out) throws IOException, FileNotFoundException {
File[] fileList = new File(sourceDir).listFiles();
if (fileList.length == 0) { // empty directory / empty folder
ZipEntry entry = new ZipEntry(sourceDir.replace(rootDir, "") + "/");
@sdpatil
sdpatil / SparkKafka10.java
Created January 11, 2017 19:04
Sample Spark Java program that reads messages from kafka and produces word count - Kafka 0.10 API
package com.test;
import com.test.schema.ContactType;
import org.apache.kafka.clients.consumer.ConsumerConfig;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.apache.spark.SparkConf;
import org.apache.spark.api.java.JavaPairRDD;
import org.apache.spark.api.java.function.*;
import org.apache.spark.streaming.Durations;
import org.apache.spark.streaming.api.java.JavaDStream;
@zhmz1326
zhmz1326 / csvDuplicateCheck.py
Created July 22, 2015 05:57
Check duplicate by key in csv file, and then print the duplicate lines out.
import codecs
filename = 'input.csv'
# fr = open(filename)
fr = codecs.open(filename,"r","shift_jis")
lines = fr.readlines()
lines.sort()
dict = {}
@Starefossen
Starefossen / remoteDataTableView.swift
Last active January 16, 2023 09:50
Remote JSON Data to tableView in iOS 8.0 (Swift)
import UIKit
import Foundation
import XCPlayground
XCPSetExecutionShouldContinueIndefinitely()
class RemoteAPI {
func getData(completionHandler: ((NSArray!, NSError!) -> Void)!) -> Void {
let url: NSURL = NSURL(string: "http://itunes.apple.com/search?term=Turistforeningen&media=software")
let ses = NSURLSession.sharedSession()
@zarkosusnjar
zarkosusnjar / gist:1675843
Created January 25, 2012 11:08
Aggregate concatenation - returning grouped rows as delimited list in DB2, AS400
create table t1 (num int, color varchar(10));
insert into t1 values (1,'red'), (1,'black'), (2,'red'), (2,'yellow'), (2,'green');
select num,
substr( xmlserialize( xmlagg( xmltext( concat( ', ', color ) ) ) as varchar( 1024 ) ), 3 )
from t1
group by num;
--OR without space after comma
@froop
froop / ZenkakuUtils.java
Created October 5, 2011 01:25
[Java] 全角の数字・小数点記号・マイナス記号を半角に変換
public static String toHankakuNum(String text) {
StringBuilder res = new StringBuilder();
final String listZens = "0123456789.-";
final String listHans = "0123456789.-";
for (int textIdx = 0; textIdx < text.length(); textIdx++) {
char ch = text.charAt(textIdx);
int listIdx = listZens.indexOf(ch);
if (listIdx >= 0) {
res.append(listHans.charAt(listIdx));
@basuke
basuke / gen-security.php
Created April 20, 2011 10:08
Generate CakePHP configuration value for security, Security.salt and Security.cipherSeed.
<?php
$salt = genrandom(40);
$seed = genrandom(29, "0123456789");
echo "\tConfigure::write('Security.salt', '$salt');\n";
echo "\tConfigure::write('Security.cipherSeed', '$seed');\n";
function genrandom($len, $salt = null) {
if (empty($salt)) {
@seyan
seyan / P327Test.java
Created April 12, 2011 06:41
ソルトを用いたパスワードのハッシュ化:レインボークラックなどへの対策
import static org.junit.Assert.assertFalse;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Test;