Skip to content

Instantly share code, notes, and snippets.

View WimJongeneel's full-sized avatar
:octocat:

Wim Jongeneel WimJongeneel

:octocat:
View GitHub Profile
const parseRequest = (s: string): Request => {
const [firstLine, rest] = divideStringOn(s, '\r\n')
const [method, url, protocol] = firstLine.split(' ', 3)
const [headers, body] = divideStringOn(rest, '\r\n\r\n')
const parsedHeaders = headers.split('\r\n').reduce((map, header) => {
const [key, value] = divideStringOn(header, ': ')
return map.set(key, value)
}, new Map())
return { protocol, method, url, headers: parsedHeaders, body }
}
export interface Request {
protocol: string
method: string
url: string
headers: Map<string, string>
body: string
}
GET / HTTP/1.1
Host: localhost:3000
curl 127.0.0.1:3000
hello world%
net.createServer()
.listen(PORT, IP, BACKLOG)
.on('connection', socket => socket
.on('data', buffer => {
const request = buffer.toString()
socket.write('hello world')
socket.end()
})
net.createServer()
.listen(PORT, IP, BACKLOG)
.on('connection', socket =>
console.log(`new connection from ${socket.remoteAddress}:${socket.remotePort}`
)
import * as net from 'net'
const PORT = 3000
const IP = '127.0.0.1'
const BACKLOG = 100
net.createServer()
.listen(PORT, IP, BACKLOG)
(b: Fake<Blog>) => b.Id.equals(1).and(b.Title.includes('hello'))
fromArray<Blog>([
{ Id: 1, Title: 'Blog 1' },
{ Id: 2, Title: 'Blog 2' },
{ Id: 3, Title: 'Blog 3' },
])
.where(b => b.Id.equals(1).and(b.Title.includes('hello')))
.toArray()
const fromArray = <T extends object>(a: Array<T>): IQueryable<T> => {
const exprs: Expr[] = []
const value = [...a]
return {
where(predicate) {
exprs.push(predicate(builder()).GetExpr())
return this
},
toArray() {