Skip to content

Instantly share code, notes, and snippets.

View DavyLin's full-sized avatar
💭
I may be slow to respond.

davylin DavyLin

💭
I may be slow to respond.
View GitHub Profile
@suweya
suweya / FileUtil.java
Last active February 17, 2023 03:39
OkHttp download file by Okio
import android.os.Environment;
import android.support.annotation.NonNull;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.concurrent.TimeUnit;
@killme2008
killme2008 / pipe.exs
Created November 20, 2015 02:09
Clojure thread macro '->>' in elixir
defmodule Pipe do
defmacro a|>b do
pos = tuple_size(b) -1
Macro.pipe(a, b, pos)
end
defmacro __using__(_extras) do
quote do
import Kernel, except: [|>: 2]
import Pipe
@killme2008
killme2008 / my_sigis.exs
Created October 23, 2015 04:14
Elixir custom sigis example
defmodule MySigils do
def sigil_i(string, []), do: String.to_integer(string)
def sigil_i(string, [?n]), do: -String.to_integer(string)
end
@killme2008
killme2008 / blank.exs
Created October 23, 2015 04:03
Elixir protocols example
defprotocol Blank do
@doc "Returns true if data is considered blank/empty"
@fallback_to_any true
def blank?(data)
end
defimpl Blank, for: Any do
def blank?(_), do: false
end
@killme2008
killme2008 / unless.exs
Created October 23, 2015 03:55
Elixir macro example
defmodule MyUnless do
defmacro unless(clause, then_clause, else_clause \\ nil) do
quote do
if !unquote(clause) do
unquote(then_clause)
else
unquote(else_clause)
end
end
end
@killme2008
killme2008 / tw_test.clj
Last active August 29, 2015 14:00
ThoughtWorks的代码题 https://www.jinshuju.net/f/EGQL3D
;;Code for https://www.jinshuju.net/f/EGQL3D
(defn- read-n-numbers [n]
(repeatedly n #(let [x (read-line)]
(Integer/valueOf x))))
(defn- say-what [inputs words n]
(let [[x y z] inputs
rs (filter #(zero? (rem n %)) inputs)]
(cond
;;rule 5
@madan712
madan712 / DocReader.java
Last active December 29, 2022 21:27
Java program to read doc or docx file
import java.io.File;
import java.io.FileInputStream;
import java.util.List;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.extractor.WordExtractor;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.poi.xwpf.usermodel.XWPFParagraph;
public class DocReader {
(fn best-hand [card-strings]
(let [card-parser (fn [[s r]]
(let [suit ({\S :spade, \H :heart,
\D :diamond, \C :club} s)
rank (if (> (Character/digit r 10) -1)
(- (Character/digit r 10) 2)
({\T 8, \J 9,
\Q 10, \K 11, \A 12} r))]
{:suit suit, :rank rank}))
cards (map card-parser card-strings)
@ChanglinZhou
ChanglinZhou / gist:8129550
Created December 26, 2013 03:44
Palindromic Numbers
(let [exp10 #(reduce * 1 (repeat % 10))
combine (fn [n1 ev]
(loop [r n1 n2 (if ev n1 (quot n1 10))]
(if (zero? n2) r
(recur (+ (* 10 r) (rem n2 10)) (quot n2 10)))))
gen (fn gen [start end ev]
(lazy-cat
(if ev nil (map #(combine % ev) (range start end)))
(map #(combine % true) (range (if ev start (quot end 10)) end))
(gen end (* end 10) false)))
@netstu
netstu / test5
Created December 20, 2013 13:06
以下内容粘贴到“AppleScript编辑器”中,保存为“sendMsg.scpt”: 使用方法为,在“终端”中运行命令: osascript sendMsg.scpt 'iMessageId' 'flood attack' 1000 三个参数分别是“iMessage的id”, “发送内容”和“发送次数”
on run {targetBuddyPhone, targetMessage, repeatCount}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy targetBuddyPhone of targetService
set myCount to repeatCount as integer
repeat myCount times
send targetMessage to targetBuddy
end repeat
end tell
end run