Skip to content

Instantly share code, notes, and snippets.

@lsgrep
lsgrep / ui.clj
Created December 16, 2014 19:59
playing with clojure
(ns learn.ui
(:require [seesaw.core :as ui])
(:use seesaw.font)
(:require [clj-http.client :as http])
)
(def my-frame (ui/frame :title "awesome"))
(-> my-frame ui/pack! ui/show!)
@lsgrep
lsgrep / core.clj
Created December 16, 2014 20:18
playing with clojure
(ns learn.core
(:require [clojure.core.async :refer [chan sliding-buffer go go-loop
timeout >! <!]])
(:require [clojure.core.reducers :as r])
(:require [clj-http.client :as http])
(:require [org.httpkit.client :as httpkit])
(:require [clojure.java.io :as io])
(:require [net.cgrand.enlive-html :as html])
(:use [clojure.java.shell :only [sh]])
(:require [clojure.string :as str])
@lsgrep
lsgrep / core.clj
Last active August 29, 2015 14:11
lichess 中文翻译成维语
;;(:require [org.httpkit.client :as httpkit])
;;(:require [clojure.java.io :as io])
;;(:require [net.cgrand.enlive-html :as html])
(defn get-raw-translation-result [src-text ]
(apply (comp first :content ) (html/select (html/html-snippet
(:body (http/post "http://tilmach.net"
{:form-params {:Source src-text}}))) [:textarea#Target])))
(defn translate [src]
(.trim (get-raw-translation-result src)))
@lsgrep
lsgrep / custom.el
Last active August 29, 2015 14:11
prelude custom config
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(add-to-list 'package-archives '("org" . "http://orgmode.org/elpa/") t) ; Org-mode's repository
(defun ensure-package-installed (&rest packages)
"Assure every package is installed, ask for installation if it’s not.
Return a list of installed packages or nil for every skipped package."
(mapcar
(lambda (package)
;; (package-installed-p 'evil)
@lsgrep
lsgrep / core.clj
Last active August 29, 2015 14:11
Google scholar crawler
;; scraping google scholar
(def ^:dynamic scholar-base "http://scholar.google.com/scholar?q=")
(def start-url "http://scholar.google.com/scholar?q=machine++learning")
(def typical-url "http://scholar.google.com/scholar?q=machine++learning&start=10")
(defn rebuild-keywords [keyword]
(.replace (.trim keyword) " " "+"))
@lsgrep
lsgrep / lichess-2.ug
Created December 20, 2014 10:42
Lichess translation
playWithAFriend=和朋友下棋
دوستۇم بىلەن شاھمات ئوينايمەن
playWithTheMachine=和机器下棋
ماشىنا شاھمات ئوينايمەن
toInviteSomeoneToPlayGiveThisUrl=要邀请别人下棋,请给他这个网址
باشقىلارنى تەكلڭىپ قىلىمەن ​,‌ تور ئادرېسىنى يوللا
gameOver=游戏结束
ئويۇن ئاخىرلاشتى
waitingForOpponent=等待对手
رەقىبنى ساقلاش
@lsgrep
lsgrep / core.clj
Created December 22, 2014 13:56
Clojure Download a file
(defn download-file [url dir]
(let [my-file (last (.split url "/"))]
(if-not (.exists (io/as-file (str dir my-file)))
(try
(with-open [ in (io/input-stream url)
out (io/output-stream (str dir my-file))]
(io/copy in out)
(println my-file " has been downloaded.")
)
(catch Exception e (str "caught exception:" (.getMessage e))))
@lsgrep
lsgrep / *scratch*.el
Created January 22, 2015 17:49
Nginx Security and Remote Addr
server{
listen 80;
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
server_name asdf;
location /{
proxy_set_header X-Real-IP $remote_addr;
@lsgrep
lsgrep / *scratch*.el
Created January 22, 2015 19:34
Run ElasticSearch Docker Container local
;;iptables,this does not work for docker . You have to set ip explicitly
sudo iptables -A INPUT -p tcp -s localhost --dport 9200 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 9200 -j DROP
;; starting elasticsearch in a secure fashion
sudo docker run --name elastic -d -p 127.0.0.1:9200:9200 -p 127.0.0.1:9300:9300 -v /elastic:/data dockerfile/elasticsearch /elasticsearch/bin/elasticsearch -Des.config=/data/elasticsearch.yml
@lsgrep
lsgrep / custom.el
Created February 10, 2015 20:20
emacs compress current buffer
(defun yui-compress ()
(interactive)
(call-process-region
(point-min) (point-max) "yuicompressor" t t nil (buffer-file-name)))