Skip to content

Instantly share code, notes, and snippets.

@qingniufly
qingniufly / gist:fbb6165e17e095e59ff7b3120aca314f
Created February 13, 2017 08:48 — forked from Bouke/gist:10454272
Install FreeTDS, unixODBC and pyodbc on OS X

First, install the following libraries:

$ brew install unixodbc
$ brew install freetds --with-unixodbc

FreeTDS should already work now, without configuration:

$ tsql -S [IP or hostname] -U [username] -P [password]
locale is "en_US.UTF-8"

locale charset is "UTF-8"

@qingniufly
qingniufly / parquet_spark.scala
Created March 1, 2017 10:10
spark read and write parquet files
// read
val filePath = "file:///path/to/spark/examples/src/main/resources/users.parquet"
val users = sqlContext.read.load(filePath)
// write
val personJsonFile = "file:///path/to/spark/examples/src/main/resources/people.json"
val personDF = sqlContext.read.json(personJsonFile)
personDF.select("name", "age").write.format("parquet").save("file:///tmp/new_people.parquet")
@qingniufly
qingniufly / ExecutorServiceTest.java
Created March 10, 2017 02:07
java Executors ExecutorService
ExecutorService es = Executors.newCachedThreadPool();
ExecutorCompletionService<Boolean> ecs = new ExecutorCompletionService<>(es);
Set<Future> futureSet = new HashSet<Future>();
List<Callable> callerList = new ArrayList<Callable>();
// 构造任务列表
for (int i = 0; i < 100; i++) {
callerList.add(...);
}
@qingniufly
qingniufly / shell-example.sh
Created March 10, 2017 02:32
shell, sed, awk
# 循环
for i in {1..100}; do echo $i; done
for i in $(seq 1 100); do echo $i; done
for ((i = 0; i < 100; i++)); do echo $i; done
# sed 读取文件 a,b行的内容
sed -n '5,10p' test.txt
# 删除空行
sed '/^$/d' file
@qingniufly
qingniufly / ReflectHelpers.java
Created March 15, 2017 07:00
ClassLoader, Reflect
public class ReflectHelpers {
public static ClassLoader findClassLoader() {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
if(classLoader == null) {
classLoader = ReflectHelpers.class.getClassLoader();
}
if(classLoader == null) {
classLoader = ClassLoader.getSystemClassLoader();
ClassLoader CLASS_LOADER = ReflectHelpers.findClassLoader();
TreeSet pipelineRunnerRegistrars = Sets.newTreeSet(ObjectsClassComparator.INSTANCE);
Lists.newArrayList(ServiceLoader.load(PipelineRunnerRegistrar.class, CLASS_LOADER));
@qingniufly
qingniufly / ByteBufferConverter.java
Created March 28, 2017 07:31
Java NIO, ByteBuffer <--> String
// ByteBuffer to String
String s = Charset.forName("UTF-8").decode(byteBuffer).toString();
// String to ByteBuffer
ByteBuffer buff = Charset.forName("UTF-9").encode("Hello, World!");
// String to ByteBuffer
public static ByteBuffer str_to_bb(String msg, Charset charset){
return ByteBuffer.wrap(msg.getBytes(charset));
@qingniufly
qingniufly / CopyFile.java
Created March 28, 2017 07:42
Java NIO file ops
import java.io.FileInputStream;
import java.io.FileOutputStream;
public class CopyFile {
public static void main(String[] args) {
String infname = "/tmp/in.txt";
String outfname = "/tmp/out.txt";
FileInputStream fis = new FileInputStream(infname);
FileOutputStream fos = new FileOutputStream(outfname);
@qingniufly
qingniufly / NIOEchoServer.java
Last active March 29, 2017 09:09 — forked from komamitsu/gist:1528682
NIO Echo Server
package com.komamitsu;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;
@qingniufly
qingniufly / git-tag-delete-local-and-remote.sh
Created June 22, 2017 10:20 — forked from mobilemind/git-tag-delete-local-and-remote.sh
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName