Skip to content

Instantly share code, notes, and snippets.

View killme2008's full-sized avatar
🎯
Focusing

dennis zhuang killme2008

🎯
Focusing
View GitHub Profile
@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
/* *******************************************
// LICENSE INFORMATION
// The code, "Detecting Smartphones Using PHP"
// by Anthony Hand, is licensed under a Creative Commons
// Attribution 3.0 United States License.
//
// Updated 01 March 2010 by Bryan J Swift
// - Remove un-needed if statements instead just returning the boolean
// inside the if clause
//
/* *******************************************
// LICENSE INFORMATION
// The code, "Detecting Smartphones Using PHP"
// by Anthony Hand, is licensed under a Creative Commons
// Attribution 3.0 United States License.
//
// Updated 01 March 2010 by Bryan J Swift
// - Remove un-needed if statements instead just returning the boolean
// inside the if clause
//
@killme2008
killme2008 / gist:3003145
Created June 27, 2012 10:13
Java throw even checked exceptions without being required to declare them or catch them.
/**
* Throw even checked exceptions without being required
* to declare them or catch them. Suggested idiom:
* <p>
* <code>throw sneakyThrow( some exception );</code>
*/
static public RuntimeException sneakyThrow(Throwable t) {
// http://www.mail-archive.com/javaposse@googlegroups.com/msg05984.html
if (t == null)
throw new NullPointerException();
@killme2008
killme2008 / .emacs
Created August 7, 2012 10:57
dot.emacs
;;; This was installed by package-install.el.
;;; This provides support for the package system and
;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
(add-to-list 'load-path "~/.emacs.d/marmalade")
(require 'package)
(add-to-list 'package-archives '("marmalade" . "http://marmalade-repo.org/packages/"))
(package-initialize)
';;使用缩写模式
@killme2008
killme2008 / joy-of-clojure-lazy-qsort.clj
Created September 29, 2012 12:05 — forked from noahlz/joy-of-clojure-lazy-qsort.clj
Lazy QuickSort implementation in Clojure, from Joy of Clojure chapter 6.
(ns joy.q)
;; nil
(defn nom [n] (take n (repeatedly #(rand-int n))))
;; #'joy.q/nom
(defn sort-parts [work]
(lazy-seq
(loop [[part & parts] work] ;; Pull apart work - note: work will be a list of lists.
(if-let [[pivot & xs] (seq part)] ;; This blows up unless work was a list of lists.
@killme2008
killme2008 / monads.clj
Created November 24, 2012 17:11 — forked from martintrojer/monads.clj
The M word
(ns monads
(:require clojure.set))
(declare ^:dynamic return
^:dynamic bind)
(defn lift-inc [v]
(return (inc v)))
(defn m-add [mv n]
@killme2008
killme2008 / CounterSupervisor.exs
Created October 23, 2015 03:46
Elixir supervisor example
defmodule CounterSupervisor do
use Supervisor
def start_link(v \\ 0) do
Supervisor.start_link(__MODULE__, v)
end
@counter_name Counter
#supervisor callback
def init(v) do
@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 / 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