Skip to content

Instantly share code, notes, and snippets.

@hyone
hyone / gist:3164085
Created July 23, 2012 15:00
Scraping Twitter API XML
module Main where
import Control.Applicative
import Control.Monad
import Data.Maybe (fromJust, isJust)
import Network.Curl (curlGetString, URLString)
import qualified Text.XML.Light as XML
url = "http://search.twitter.com/search.atom?q=haskell&rpp=10"
@hyone
hyone / gist:2776665
Created May 23, 2012 17:54
Inverse FizzBuzz by Scala
object InverseFizzBuzz extends App {
implicit def makeSeqSafer[A](xs: Seq[A]) = new {
def safeMinBy[B](f: A => B)(implicit cmp: Ordering[B]) =
if (xs.nonEmpty) Some(xs.minBy(f)) else None
}
def solve(words: Seq[String]): Option[(Int, Int)] = {
List(3,5,6,9,10,12,15).flatMap { x =>
val (subseq, pos) = Stream.from(x).collect {
@hyone
hyone / gist:2751567
Created May 20, 2012 05:31
Inverse FizzBuzz by Clojure #2
;; Inverse Fizzbuzz - just another scala quant - http://www.jasq.org/2/post/2012/05/inverse-fizzbuzz.html
(ns inverse-fizzbuzz.core
(:use [clojure.test :only (deftest are)]))
(defn unzip [coll]
(if-not (empty? coll)
(apply map list coll)))
@hyone
hyone / gist:2707327
Created May 16, 2012 04:13
Inverse FizzBuzz by Clojure
;; Inverse Fizzbuzz - just another scala quant - http://www.jasq.org/2/post/2012/05/inverse-fizzbuzz.html
;; UPDATED 2012/05/20: This code is wrong, because this only finds the index of the first sub sequence of fizzbuzz sequence.
(ns inverse-fizzbuzz.core)
(defn fizzbuzz []
(map #(cond (zero? (mod % 15)) "fizzbuzz"
(zero? (mod % 3)) "fizz"
(zero? (mod % 5)) "buzz"
@hyone
hyone / gist:1835356
Created February 15, 2012 12:24
Multiple async HTTP requests by aleph
;; (defproject async-test2 "1.0.0-SNAPSHOT"
;; :description "FIXME: write description"
;; :dependencies [[org.clojure/clojure "1.3.0"]
;; [aleph "0.2.1-alpha1"]])
(ns async-test2.core
(:use lamina.core
aleph.http))
@hyone
hyone / gist:1711460
Created January 31, 2012 16:33
Multiple async HTTP requests by http.async.client
;; (defproject async-test1 "1.0.0-SNAPSHOT"
;; :description "FIXME: write description"
;; :dependencies [[org.clojure/clojure "1.3.0"]
;; [http.async.client "0.4.0"]]
;; :dev-dependencies [[swank-clojure "1.3.4"]])
(ns async-test1.core
(:require [http.async.client :as client]
[http.async.client.request :as request]))
@hyone
hyone / gist:1705182
Created January 30, 2012 16:10
Check expression context
use v5.14;
use warnings;
sub hoge {
say do {
given (wantarray) {
when (undef) { "void" }
when (0) { "scalar" }
when (1) { "list" }
}
@hyone
hyone / gist:1689488
Created January 27, 2012 16:03
Run prove command on *.t file in quickrun.el
;; use prove on *.t file
(quickrun-add-command "perl/test"
'((:command . "prove")
(:exec . "%c -v %s")
(:description . "Run Perl Test script")))
(add-to-list 'quickrun-file-alist '("\\.t$" . "perl/test"))
@hyone
hyone / gist:1689469
Created January 27, 2012 16:00
Fix the problem output don't display in quickrun.el
(defadvice quickrun/apply-outputter (after quickrun/fix-scroll-buffer activate)
(recenter))
@hyone
hyone / gist:1645612
Created January 20, 2012 06:04
Fix syntax to work with slime repl (clojure) with paredit
;; From https://github.com/overtone/live-coding-emacs/blob/master/lib/durendal/durendal.el
(defun clojure-slime-repl-fix-syntax ()
(modify-syntax-entry ?\{ "(}")
(modify-syntax-entry ?\} "){")
(modify-syntax-entry ?\[ "(]")
(modify-syntax-entry ?\] ")[")
(modify-syntax-entry ?~ "' ")
(modify-syntax-entry ?, " ")
(modify-syntax-entry ?^ "'")