Skip to content

Instantly share code, notes, and snippets.

View gingerhot's full-sized avatar
🎯
Focusing

B1nj0y gingerhot

🎯
Focusing
View GitHub Profile
@gingerhot
gingerhot / yt-stream
Created August 17, 2016 08:33 — forked from superbarne/yt-stream
Streams youtube videos directly to the browser like a proxy
var ytdl = require('ytdl')
function stream(req,res,id) {
var dl = ytdl('http://www.youtube.com/watch?v='+id, {
quality:43 //poor quality leave empty for good quality
})
dl.pipe(res);
}
@gingerhot
gingerhot / gist:f5e91493e63d3f4d8ebaf57c372be75f
Created September 3, 2016 20:05 — forked from TerrorJack/gist:7ea3f024c141ac14425d
Handwritten packrat parser for trivial integer arithmetic expressions.
{-
Handwritten packrat parser for trivial integer arithmetic expressions. Guarantees O(n) time/space complexity.
Rule: Exp <- IntVal / (Exp) / (+ Exp Exp) / (- Exp Exp) / (* Exp Exp)
Examples: " 233 ", "( + 42 ((233) ) )", "( (* 42 (+ 1 233)) )".
Properly handles whitespaces. "2 33" will not be recognized as 233.
-}
import Data.Char
data Node = Nil | Node {next::Node,char::Char,skipped::Node,result::Result}
@gingerhot
gingerhot / gist:560a530fada1ea90fb65e50df1f26143
Created September 3, 2016 20:06 — forked from TerrorJack/gist:dacc375125c6ff1a38ff
Naive PEG parser without memoization
import Data.Char
newtype Parser a = Parser (String -> [(a,String)])
parse :: Parser a -> String -> ([(a,String)])
parse (Parser p) inp = p inp
instance Monad Parser where
return val = Parser (\inp -> [(val,inp)])
pa >>= f = Parser (\inp ->
@gingerhot
gingerhot / Session
Created September 4, 2016 09:30 — forked from BorePlusPlus/Session
Setuid/Getuid in golang
$ go build setuid.go
$ sudo su
[sudo] password for bore:
# chown root:root setuid
# chmod u+s setuid
$ ./setuid
Real UID: 1000
Effective UID: 0
Real UID: 1000
Effective UID: 1000
@gingerhot
gingerhot / stock.hs
Created December 13, 2016 03:08 — forked from oz/stock.hs
Playing with Yahoo's stock API in Haskell, use this little program to quickly check stock prices, or change currencies.
import Prelude
import System.Environment
import Network.HTTP
import Control.Monad
showUsage :: IO ()
showUsage = do
putStrLn "Usage: stock <options...>\n"
putStrLn " - get a quote: stock <symbol>"
putStrLn " - change money: stock <from> <to> <amount>"
@gingerhot
gingerhot / db.go
Created May 2, 2017 01:13 — forked from troyk/db.go
golang sql query abstraction
package db
import (
"database/sql"
"log"
"strings"
"sync"
_ "github.com/lib/pq" // required for database/sql
"golang.org/x/net/context"
@gingerhot
gingerhot / puma.monitrc
Created June 30, 2017 05:03 — forked from sudara/puma.monitrc
Example config needed to use monit with puma, monitoring workers for mem.
# this monit config goes in /etc/monit/conf.d
check process puma_master
with pidfile /data/myapp/current/tmp/puma.pid
start program = "/etc/monit/scripts/puma start"
stop program = "/etc/monit/scripts/puma stop"
group myapp
check process puma_worker_0
with pidfile /data/myapp/current/tmp/puma_worker_0.pid
See question on stack overflow: http://stackoverflow.com/questions/28595636/rails-4-how-to-give-alias-names-to-includes-and-joins-in-active-record-que
- Model Student and model Teacher are both STI models with super class model User
- Model Story is a STI model with super class model Task
- includes() and joins(), both fails
Rails alias naming convention (includes() and joins())
- One model as parameter
- is base model (includes(:users))
@gingerhot
gingerhot / proxy_copy.go
Created August 27, 2017 03:17 — forked from jbardin/proxy_copy.go
Go TCP Proxy pattern
package proxy
import (
"io"
"log"
"net"
)
func Proxy(srvConn, cliConn *net.TCPConn) {
// channels to wait on the close event for each connection
@gingerhot
gingerhot / proxy.go
Created August 27, 2017 03:18 — forked from vmihailenco/proxy.go
Simple TCP proxy in Golang
package main
import (
"bytes"
"encoding/hex"
"flag"
"fmt"
"io"
"log"
"net"