Skip to content

Instantly share code, notes, and snippets.

Avatar

albert lai zerg000000

  • Moovup
  • Hong Kong
View GitHub Profile
@zerg000000
zerg000000 / user.clj
Last active Jun 26, 2021
S3 presign (post) example aws-api
View user.clj
(require '[buddy.core.codecs.base64 :as base64]
'[cognitect.aws.util :as util]
'[clojure.string :as str]
'[jsonista.core :as json]
'[cognitect.aws.credentials :as creds]
'[cognitect.aws.http :as http])
(import '[java.util Date])
(defn host-style-bucket-uri [bucket]
(str "http://" bucket ".s3.amazonaws.com/"))
@zerg000000
zerg000000 / deps.edn
Last active Sep 20, 2019
OHLC in Clojure
View deps.edn
{:deps {net.cgrand/xforms {:mvn/version "0.19.0"}
org.clojure/clojure {:mvn/version "1.10.1"}
org.clojure/core.async {:mvn/version "0.4.500"}}}
View graph.clj
(require '[clojure.set :as s])
;; Graph Data from the Picture
(def graph [#{:a :b}
#{:a :d}
#{:a :h}
#{:b :c}
#{:b :d}
#{:d :c}
#{:d :e}
View Learn Clojure - Simple Guess Game
;; P.S. 閱讀指引,在 Code Snippet(白色的地方)按Ctrl+Enter看結果。也可以修改後按Ctrl+Enter~
;; 假設我想寫一個簡單的猜字遊戲。
;; 首先,我應該要有一本字典提供生字。
(def dict ["Clojure" "Java" "Go" "Javascript" "Haskell" "Scala" "C" "C++" "Rust" "C#" "Prolog"])
@zerg000000
zerg000000 / project.clj
Created Feb 9, 2017
How to clojail a symbol
View project.clj
(defproject test-cljail "0.1.0-SNAPSHOT"
:description "FIXME: write description"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[clojail "1.0.6"]])
@zerg000000
zerg000000 / repl.clj
Last active Mar 25, 2016
考起碩士生的小一數學題(ppp)解法 - 香港高登 http://m2.hkgolden.com/view.aspx?message=6307521&type=SW&page=1
View repl.clj
(use 'clojure.core.logic)
(require '[clojure.core.logic.fd :as fd])
(def result
(run* [q]
(fresh [a b c d e f g h p ab cd ef gh ppp]
(fd/in a b c d e f g h p (fd/interval 1 9)) ; why not zero?
(fd/in ab cd ef gh (fd/interval 10 99))
(fd/in ppp (fd/interval 100 999))
(fd/eq
View EverythingHardCoded.java
public class Mailer {
public void send(String content) {
String to = "abcd@gmail.com";
String from = "web@gmail.com";
String host = "localhost";
// Get system properties
Properties properties = System.getProperties();
View lessTrickyToString.js
// Parameter Object opts instead of withQuot and withComma
function trickyToString(data, opts) {
//trickyToString become a Template method
// quot and comma flag become Strategy of trickyToString method
var quotFunc = opts.withQuot || function(s){ return s; };
var commaFunc = opts.withComma || function(){ return ","; };
var outStr = "";
for( key in data ) {
outStr = outStr + quotFunc(key) + commaFunc() + quotFunc(data[key]) + "\n";
}
View trickyToString2.js
function trickyToString(data, withComma, withQuot) {
var outStr = "";
for( key in data ) {
outStr = outStr + quot(key, withQuot);
if(withComma) {
if(withQuot) {
outStr = outStr + "," + quot(data[key], withQuot);
} else {
outStr = outStr + ",";
}
View trickyToString.js
function trickyToString(data, withComma) {
var outStr = "";
for( key in data ) {
outStr = outStr + key;
if(withComma) {
outStr = outStr + "," + data[key];
} else {
outStr = outStr + ";" + data[key];
}
outStr = outStr + "\n";