Skip to content

Instantly share code, notes, and snippets.

View lmatt-bit's full-sized avatar
🎱

lmatt lmatt-bit

🎱
View GitHub Profile
@lmatt-bit
lmatt-bit / sql
Created March 1, 2016 06:37
SELECT top 1 from a group (SQL Server)
SELECT a, b, c
FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY a ORDER BY b, c) rn
FROM mytable
) q
WHERE rn = 1
ORDER BY
a
@lmatt-bit
lmatt-bit / FSharp.Chart.Gtk.example.fsx
Created November 15, 2015 14:15
FSharp script to run fsharp.chart.gtk
open System
//#I "packages/FSharp.Data.2.2.5/lib/net40"
#I "packages/FSharp.Charting.Gtk.0.90.12/lib/net40"
#load "packages/FSharp.Charting.Gtk.0.90.12/FSharp.Charting.Gtk.fsx"
#r "packages/FSharp.Data.2.2.5/lib/net40/FSharp.Data.dll"
open FSharp.Charting
open FSharp.Data
@lmatt-bit
lmatt-bit / StackOverflowApi.fs
Created November 14, 2015 09:15
Use Type Provider to query Statck overflow api
open System
open FSharp.Data
type Questions = JsonProvider<"""https://api.stackexchange.com/2.2/questions?site=stackoverflow""">
let csQuestions = """https://api.stackexchange.com/2.2/questions?site=stackoverflow&tagged=C%23"""
let getResult =
Questions.Load(csQuestions).Items |> Seq.iter (fun x -> Console.WriteLine x.Title)
@lmatt-bit
lmatt-bit / randomForest.fs
Created November 10, 2015 14:27
randomForest in FSharp with RProvider. The data is from the digit recongizer of Kaggle.
open RProvider.utils
R.install_packages("randomForest") |> ignore
open System
open Deedle
open RDotNet
open RProvider
open RProvider.``base``
open RProvider.stats
open RProvider.randomForest
@lmatt-bit
lmatt-bit / gist:ed632e481f7a3844c902
Last active August 29, 2015 14:19
Seq related functions
//below line read all lines until eof reach
let lines = Seq.initInfinite (fun _ -> System.Console.In.ReadLine()) |> Seq.takeWhile(fun line -> line <> null)
//below code read all lines and parse as int and print
Seq.initInfinite (fun _ -> System.Console.In.ReadLine()) |> Seq.takeWhile(fun line -> line <> null) |> Seq.map(fun v -> System.Int32.Parse(v)) |> Seq.iter(fun v -> printfn "%i" v)
//iter, iteri, iter2
let seq1 = [1; 2; 3]
let seq2 = [4; 5; 6]
Seq.iter (fun x -> printfn "Seq.iter: element is %d" x) seq1
let rec sum n = if n=0 then 0 else n + sum(n - 1)
sum(10).Dump() //This is for LinqPad
http://d.stavrovski.net/blog/post/how-to-install-and-setup-oracle-java-jdk-in-centos-6
# rpm
wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"http://download.oracle.com/otn-pub/java/jdk/7u55-b13/jdk-7u55-linux-x64.rpm" \
-O jdk-7-linux-x64.rpm
# ubuntu
@lmatt-bit
lmatt-bit / gist:3b181fb879cd54792241
Created February 21, 2015 10:22
Tornado AsyncHttpClient simple example
#from tornado.httpclient import HTTPClient
from tornado.httpclient import AsyncHTTPClient
import tornado.ioloop
#client = HTTPClient()
#res = client.fetch("http://www.baidu.com")
#print res.body
def handle_res(res):
@lmatt-bit
lmatt-bit / gist:218ba1733f6beae369c5
Created February 18, 2015 08:22
Use yield to implement coroutine
def coroutine(func):
def start(*args, **kwargs):
cr = func(*args, **kwargs)
cr.next()
return cr
return start
@coroutine
def grep(pattern):
print "looking for %s" % pattern
@lmatt-bit
lmatt-bit / gist:1642dab91aadce5c22a4
Created January 9, 2015 03:10
Handle default namespace in xml
from lxml import etree
from StringIO import StringIO
s = '''<?xml version="1.0" encoding="UTF-8"?>
<Environment
xmlns="http://schemas.dmtf.org/ovf/environment/1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:oe="http://schemas.dmtf.org/ovf/environment/1"
xmlns:ve="http://www.vmware.com/schema/ovfenv"
oe:id=""