Skip to content

Instantly share code, notes, and snippets.

@qzchenwl
qzchenwl / LLRBTree.hs
Last active December 11, 2015 05:39
Implemention of Left Leaning Red Black Tree, see http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf
{-# LANGUAGE BangPatterns #-}
module LLRBTree where
import Data.List (foldl', nub, (\\))
import qualified Data.List as L
import Data.Maybe
import System.Cmd
import Prelude hiding (minimum)
import Debug.Trace
import Test.QuickCheck
// ==UserScript==
// @name Duomi Download
// @namespace http://diveintogreasemonkey.org/download/
// @description Easy to download duomi music
// @include http://huodong.duomi.com/*
// ==/UserScript==
var unsafeWindow = (function () {
var dummyElem = document.createElement('p');
dummyElem.setAttribute('onclick', 'return window;');
@qzchenwl
qzchenwl / pingpong-0.hs
Last active December 15, 2015 10:18
Glimpse of Cloud Haskell http://www.well-typed.com/blog/68
{-# LANGUAGE DeriveDataTypeable #-}
module Main where
import Control.Concurrent ( threadDelay )
import Data.Binary
import Data.Typeable
import Control.Distributed.Process
import Control.Distributed.Process.Node
<?php
$param1 = "哈哈1\t𤭢2\\3\"";
$param2 = "10";
$param11 = "哈\xd5\"哈1\t𤭢2\\3\"";
$param22 = "10 union 1,2";
$sql1 = "select * from user where username=" . literal($param1) . " and age=" . literal(intval($param2));
$sql2 = "select * from user where username=" . literal($param1) . " and age=" . literal($param2);
$sql3 = "select * from user where username=" . literal($param11) . " and age=" . literal(intval($param2));
import Data.List
floors = 0 : 1 : map step [2..]
where step h = minimum [ 1 + max (x-1) (floors!!(h-x)) | x <- [1..h-1] ]
main = print $ take 200 floors
@qzchenwl
qzchenwl / Test.java
Created August 14, 2013 03:06
Stream implemented in java
package util;
import org.springframework.util.Assert;
import java.math.BigDecimal;
import java.util.Iterator;
public class Test {
public static void main(String[] args) {
#include <iostream>
#include <string>
#include <sstream>
#include <fstream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
@qzchenwl
qzchenwl / jq.hs
Created September 23, 2013 09:23
JSON Parser
module Main where
import Text.ParserCombinators.Parsec
import Control.Applicative ((*>), (<*), (<*>), (<$>), (<$), empty)
import Numeric (readHex, readSigned, readFloat)
run :: Show a => Parser a -> String -> IO ()
run p input = case (parse p "" input) of
Left err -> do putStr "parse error at "
print err
module Main where
-----------------------------------------------------------------------------
---- |
----
---- 输出最长回文子串, 直观版。
----
-------------------------------------------------------------------------------
import Data.List (maximumBy)
import Data.Function (on)
-- http://blog.tmorris.net/posts/20-intermediate-haskell-exercises/
module Main where
class Fluffy f where
furry :: (a -> b) -> f a -> f b
-- Exercise 1
-- Relative Difficulty: 1
instance Fluffy [] where
furry _ [] = []