Skip to content

Instantly share code, notes, and snippets.

@czxttkl
czxttkl / gist:7945408
Last active December 31, 2015 06:09
这是一道检测inversion count的算法。它将检测输入序列中反序输入的个数,即检测其中有几对A[i] > A[j], i < j 比如输入4,3,2,1,输出应该为3+2+1=6.。 因为: 1. 4比3,2,1大,但4在输入序列中是第一位,比3,2,1的index都小 2. 3比2,1大 3. 2比1大
#!/usr/bin/python
############################################################
#
#
# author: [email protected]
# date: 03/12/2013
# purpose: count inversions in a given array of numbers
#
#
package io.github.czxttkl.stocks.old;
import io.github.czxttkl.stocks.auxi.JS;
import io.github.czxttkl.stocks.auxi.Stock;
import io.github.czxttkl.stocks.auxi.StockGlobal;
import io.github.czxttkl.util.UtilJava;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
package io.metadata;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Scanner;
import org.apache.commons.lang.StringEscapeUtils;
import java.net.UnknownHostException;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.DBCursor;
import com.mongodb.MongoClient;
/**
* @author Zhengxing Chen
*
@czxttkl
czxttkl / shell.c
Last active November 17, 2020 10:23
/*
============================================================================
Name : sh.c
Author : Zhengxing Chen
Version :
Copyright : czxttkl. Achieve Shell basic functions: execution, IO redirection and Pipe.
============================================================================
*/
#include <stdlib.h>
#include <unistd.h>
import java.util.Arrays;
public class TestAnything {
public static void main(String[] args) throws Exception {
int[] seqs = new int[] { 1, 2, 3, 4, 5, 6 };
int[] pointers = new int[] { 0, 1, 2 };
while (!isExhausted(pointers, seqs.length)) {
public class TestAnything {
public static void main(String[] args) throws Exception {
Object[] a = new Object[2];
a[0] = (Object)"aaaa";
a[1] = (Object)"bbbb";
String[] b = convertLsy(a, String.class);
}
private static <T> T[] convertLsy(Object[] a, Class<T> cls) {
@SuppressWarnings("unchecked")
public static <T> T[] concatArrays8(T[] arr1, T[] arr2) {
T[] both = (T[])Array.newInstance(arr1.getClass().getComponentType(), arr1.length+arr2.length);
Object[] bothObj = Stream.concat(Arrays.stream(arr1), Arrays.stream(arr2)).toArray();
for (int i = 0; i < both.length; i++) {
both[i] = (T)bothObj[i];
}
return both;
}
@czxttkl
czxttkl / l1vsl2.py
Last active October 14, 2016 15:45
import sklearn as sklearn
import numpy as np
from sklearn.cross_validation import train_test_split
from sklearn import linear_model
# Create synthetic data
num_samples = 500
num_unrelated_features = 1000
def f(x1, x2):
package io.github.czxttkl;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
import org.apache.commons.math3.random.MersenneTwister;
import org.apache.commons.math3.random.RandomGenerator;
import org.deeplearning4j.datasets.iterator.DataSetIterator;