Skip to content

Instantly share code, notes, and snippets.

View Schniz's full-sized avatar

Gal Schlezinger Schniz

View GitHub Profile
function add2(a: number, b: number) {
return a + b;
}
function add4(a: number, b: number, c: number, d: number) {
return a + b + c + d;
}
function concat(a: string, b: string) {
return (a + b).length;
class Lens<RootObject extends object, ChangableObject> {
getter: (x: RootObject) => ChangableObject;
setter: (x: RootObject, newValue: ChangableObject) => RootObject;
static simple<RootObject extends object, T extends keyof RootObject>(
name: T
) {
return new Lens<RootObject, RootObject[T]>(
x => x[name],
(x, v) => ({ ...x, [name]: v })
@Schniz
Schniz / README.md
Last active September 18, 2018 23:51
add typed `init_with` to Crystal Crecto models

Usage

class User < Crecto::Model
  schema "users" do
    field :name, String
  end
end

user = User.init_with(name: "hello") # doesn't fail
@Schniz
Schniz / result_type.cr
Created September 18, 2018 18:02
Result type for Crystal
record Ok(O), result : O
record Err(E), error : E
## hopefully it could have been
# alias Result(O, E) = Ok(O) | Error(E)
## but it can't
def mytest(i)
if i < 0
Ok.new(i)
@Schniz
Schniz / Angle.re
Created June 23, 2018 12:44
Two-dimensional vector addition and degrees conversions
let pi = 4.0 *. atan(1.0);
type t =
| Radians(float)
| Degrees(float);
let toRadians = d =>
switch (d) {
| Radians(d) => Radians(d)
| Degrees(d) => Radians(d *. pi /. 180.)
@Schniz
Schniz / bcrypt_v2.0.0__flow_v0.69.0.js
Created April 9, 2018 21:49
opaque types for bcrypt
opaque type bcrypt$hashed = string;
declare module "bcrypt" {
declare module.exports: {
hash: (password: string, saltRounds: number) => Promise<bcrypt$hashed>,
compare: (
password: string,
hashedPassword: bcrypt$hashed
) => Promise<boolean>,
};

Keybase proof

I hereby claim:

  • I am schniz on github.
  • I am schniz (https://keybase.io/schniz) on keybase.
  • I have a public key ASAoK6wufz1Xfrm7AFF4Sbb1_pj9uagkBzRY1crIXWYI3go

To claim this, I am signing this object:

@Schniz
Schniz / jira.1m.sh
Created August 17, 2017 13:43
Jira BitBar
#!/bin/bash
#
# Install `jq` by `brew install jq`
# Make sure to have ~/dotfiles/bitbar/.env with the following env vars:
# JIRA_USERNAME=...
# JIRA_PASSWORD=...
# JIRA_BASE_URL=https://something.atlassian.net
#
@Schniz
Schniz / curry.py
Created August 14, 2017 14:05
Curry python decorator
#!/usr/bin/env python
def curry(fn):
arg_count = fn.func_code.co_argcount
def start(*initial_args):
args = []
args.extend(initial_args)
def inner(*more_args):
@Schniz
Schniz / GetCurrentLocation.jsx
Created June 25, 2017 20:46
React Native component for getting the current location. for lazy ones like me.
import React from "react";
export default class GetCurrentLocation extends React.Component {
state = {};
watchId = null;
componentDidMount() {
const options = {
enableHighAccuracy: true,
timeout: 200,