Skip to content

Instantly share code, notes, and snippets.

@qingniufly
qingniufly / sparkdemo.scala
Created August 23, 2017 04:29 — forked from timvw/sparkdemo.scala
SparkSQL and CTE for increased readability
val df = spark.read.text(inputFile)
df.createOrReplaceTempView("data")
val query =
"""
| WITH loglevel AS (SELECT SPLIT(value, ' ')[0] AS level FROM data WHERE LENGTH(value) > 0),
| levelcount AS (SELECT level, COUNT(*) as count FROM loglevel GROUP BY level)
| SELECT level, count FROM levelcount ORDER BY count DESC
""".stripMargin
@qingniufly
qingniufly / file_path_test.sh
Created June 27, 2017 05:20 — forked from feng-ming/file_path_test.sh
unix shell 判断目录/文件是否存在, 以及是否有读写权限。
shell判断文件,目录是否存在或者具有权限
#!/bin/sh
Path="/var/log/httpd/"
File="/var/log/httpd/access.log"
#这里的-x 参数判断$Path是否存在并且是否具有可执行权限
if [ ! -x "$Path"]; then
mkdir "$Path"
fi
@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
@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 / 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"