Skip to content

Instantly share code, notes, and snippets.

View king1600's full-sized avatar

King1600 king1600

View GitHub Profile
@king1600
king1600 / ffs.rs
Created August 15, 2018 20:19
Find First Bit Implementation
#![feature(asm)]
trait FindFirstBit {
fn ffs(&self) -> u8;
}
#[inline(always)]
fn supports_asm() -> bool {
cfg!(any(
target_arch = "x86",
@king1600
king1600 / client.pony
Last active July 5, 2018 03:50
Pony HTTP/1.1 client
use "net"
use "net/ssl"
use "collections"
actor HttpClient
let _env: Env
let _ssl_ctx: SSLContext
embed _connections: Map[String, _HttpConnection] = _connections.create()
new create(env: Env) =>
@king1600
king1600 / lexer.pony
Created July 3, 2018 21:24
(Language) Lexer Generator written in pony
use "regex"
class Rule[T]
let name: String
let regex: String
let _create: {(String): T^}
new create(name': String, regex': String, make: {(String): T^}) =>
name = name'
regex = regex'
@king1600
king1600 / Unsafe.pony
Created June 8, 2018 15:03
Unsafe abstractions for pony data
primitive Unsafe
fun gc() =>
@pony_triggergc[None](@pony_ctx[USize]())
fun usize[T](value: T): USize =>
Unsafe.ptr[T](consume value).usize()
fun ptr[T](value: T): Pointer[T] =>
@memcpy[Pointer[T]](value, USize(0), USize(0))
const Sql = require('mysql');
const Express = require('express');
const app = Express();
const port = process.argv[6] || '8080';
const database = process.argv[5];
const pool = Sql.createPool({
database: database,
connectionLimit: 10,
host: process.argv[2],
use @pony_ctx[Ptr]()
use @pony_alloc[Ptr](ctx: Ptr tag, size: USize)
use @pony_realloc[Ptr](ctx: Ptr tag, ptr: Ptr tag, size: USize)
use @memcpy[Ptr](dest: USize, src: USize, bytes: USize)
use @memmove[Ptr](dest: USize, src: USize, bytes: USize)
type Ptr is Pointer[U8]
type Option[T] is (T | None)
interface ByteArray
@king1600
king1600 / Json.hs
Created January 13, 2018 21:53
A Basic Json Parser for practice
import Data.Map (Map)
import Text.Read (readMaybe)
import Data.List (isPrefixOf)
import qualified Data.Map as Map
import Data.Char (isSpace, isNumber, isAlpha)
data Json =
JNull |
JBool Bool |
JInt Integer |
@king1600
king1600 / Calculator.hs
Last active January 13, 2018 21:52
A CLI Calculator with variables, functions and arithmatic
{-
King - 1/11/2018
Resources Used:
- Haskell quick docs: https://www.haskell.org/hoogle/
- Operator precedence: http://ee.hawaii.edu/~tep/EE160/Book/chap5/_28291_table577.gif
- Precedence climbing: http://www.engr.mun.ca/~theo/Misc/exp_parsing.htm#climbing
-}
module Main where
@king1600
king1600 / make.py
Created November 14, 2017 18:12
My Haskell Build script
import os
import sys
import shutil
CC = "ghc"
EXT = '.hs'
BINARY = 'app'
SAME_DIR = True
SRC_DIR = os.path.join(os.getcwd(), 'src')
BUILD_DIR = os.path.join(os.getcwd(), 'build')
@king1600
king1600 / jpack.py
Created October 21, 2017 05:35
JPack: The most of JSON and erlpack/etf
"""
JPack: The most of JSON and erlpack/etf
____.__________ _____ _________ ____ __.
| |\______ \/ _ \ \_ ___ \| |/ _|
| | | ___/ /_\ \/ \ \/| <
/\__| | | | / | \ \___| | \
\________| |____| \____|__ /\______ /____|__ \
\/ \/ \/
Copyright(c) 2017 king1600 (https://github.com/king1600)