Skip to content

Instantly share code, notes, and snippets.

View alinz's full-sized avatar
🎯
¯\_(ツ)_/¯

Ali Najafizadeh alinz

🎯
¯\_(ツ)_/¯
View GitHub Profile
@alinz
alinz / model.ts
Created October 13, 2019 12:41
Model
export class Model {
constructor(obj: any) {
for (let key in obj) {
this.unmarshal(toCamelCase(key), obj[key])
}
}
marshal(): any {
return Object.keys(this).reduce((obj: any, key: string) => {
obj[toSnakeCase(key)] = toJS(this[key])
// babel js
{
"plugins": [
["react-hot-loader/babel"],
["babel-plugin-root-import"],
[
"import", {
"libraryName": "antd",
"libraryDirectory": "es",
@alinz
alinz / golang_tls_http.go
Created July 11, 2019 19:59
Share tls config with server and client in golang
package main
import (
"bytes"
"crypto/tls"
"crypto/x509"
"io"
"io/ioutil"
"log"
"net/http"
@alinz
alinz / router.go
Created July 7, 2019 14:48
router with cors
import (
"net/http"
"github.com/go-chi/chi"
"github.com/go-chi/chi/middleware"
"github.com/goware/cors"
)
func New() chi.Router {
cors := cors.New(cors.Options{
@alinz
alinz / Fetcher.js
Created July 7, 2019 13:49
A simple Fetch implementation
const baseURL = process.env.API_ADDR || 'http://localhost/api'
export type Pagination<T> = {
meta: {
total: number
}
data: T
}
export interface Fetcher {
@alinz
alinz / Makefile
Created May 29, 2019 18:44
WebAssembly on Node.js
build:
emcc test.c -O3 -s WASM=1 -s EXPORTED_FUNCTIONS='["_add"]' -s SIDE_MODULE=1 -o test.wasm
run:
node index.js
@alinz
alinz / golang-tls.md
Created April 4, 2019 02:53 — forked from denji/golang-tls.md
Simple Golang HTTPS/TLS Examples

Moved to git repository: https://github.com/denji/golang-tls

Generate private key (.key)
# Key considerations for algorithm "RSA" ≥ 2048-bit
openssl genrsa -out server.key 2048

# Key considerations for algorithm "ECDSA" ≥ secp384r1
# List ECDSA the supported curves (openssl ecparam -list_curves)
@alinz
alinz / main.c
Created February 26, 2019 15:45 — forked from mochja/main.c
Yoga + OpenGL Example
#include <GLFW/glfw3.h>
#include <yoga/Yoga.h>
#include <stdlib.h>
int main(void)
{
GLFWwindow* window;
/* Initialize the library */
if (!glfwInit())
@alinz
alinz / product.js
Created February 22, 2019 18:40 — forked from cybercase/product.js
Python-like itertools.product function in javascript
function product() {
var args = Array.prototype.slice.call(arguments); // makes array from arguments
return args.reduce(function tl (accumulator, value) {
var tmp = [];
accumulator.forEach(function (a0) {
value.forEach(function (a1) {
tmp.push(a0.concat(a1));
});
});
return tmp;
@alinz
alinz / client.go
Created January 18, 2019 04:23 — forked from hakobe/client.go
golang unix domain socket
package main
import (
"io"
"log"
"net"
"time"
)
func reader(r io.Reader) {