Skip to content

Instantly share code, notes, and snippets.

View Pet3ris's full-sized avatar
🎯
Focusing

Peteris Erins Pet3ris

🎯
Focusing
View GitHub Profile
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@domenic
domenic / promises.md
Last active March 31, 2024 14:07
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@UnkindPartition
UnkindPartition / parsec.scm
Created October 17, 2012 07:58
Simple parser combinators in Scheme
(define (return v) (lambda (s ks kf) (ks v s)))
(define fail (lambda (s ks kf) (kf)))
; >>=
(define (bind a f)
(lambda (s ks kf)
(a s
(lambda (av s1) ((f av) s1 ks kf))
kf)))
@rxwei
rxwei / GADT.swift
Last active December 14, 2023 04:22
GADT in Swift
/// A type equality guarantee is capable of safely casting one value to a
/// different type. It can only be created when `S` and `T` are statically known
/// to be equal.
struct TypeEqualityGuarantee<S, T> {
private init() {}
/// Safely cast a value to the other type.
func cast(_ value: T) -> S {
return value as! S
}
@blole
blole / openai-gym-mcts.py
Last active June 8, 2023 19:24
Monte Carlo tree search agent for https://gym.openai.com
#!/usr/bin/env python2
import os
import gym
import sys
import random
import itertools
from time import time
from copy import copy
from math import sqrt, log
/**
*Submitted for verification at Etherscan.io on 2021-10-31
*/
// File: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/Strings.sol
// OpenZeppelin Contracts v4.3.2 (utils/Strings.sol)
pragma solidity ^0.8.0;
In this gist we will first show that we can beat the arc challenge
(http://www.paulgraham.com/arcchallenge.html), and then build the library that
shows how we did it. This gist is Literate Haskell and is of course executable. The packages needed are happstack-server and applicative-extras, installable using cabal.
Let's start with some imports (for now, you can ignore these)
> {-# LANGUAGE GADTs, TypeSynonymInstances #-}
> module ArcChallenge where
>
> import Control.Applicative
@0xNonCents
0xNonCents / .cairo
Last active February 18, 2022 08:19
Cairo vector
# @title The beginnings of Vector in Cairo
# @author 0xNonCents
# @notice Please let me know if this will save on gas compared to a @storage array
# MIT License
%builtins pedersen range_check
from starkware.cairo.common.alloc import alloc
from starkware.cairo.common.hash import hash2
from starkware.cairo.common.cairo_builtins import HashBuiltin
@brockelmore
brockelmore / pushable_array.sol
Created January 19, 2022 23:20
Pushable array datatype for solidity
// SPDX-License-Identifier: UNLICENSE
pragma solidity >=0.8.0 <0.9.0;
// NOT TESTED - USE AT YOUR OWN RISK
// Supports 32 byte word types. Could be easily extended to multiword types by
// passing in the size of the elements as well though
struct PushableArray {