Skip to content

Instantly share code, notes, and snippets.

@skaslev
skaslev / RigidbodyMassCalculator.cs
Created January 5, 2016 12:27 — forked from FreyaHolmer/RigidbodyMassCalculator.cs
Used to approximate a proper mass value for all the colliders in a given Rigidbody
using UnityEngine;
using System.Linq;
[RequireComponent(typeof(Rigidbody))]
public class RigidbodyMassCalculator : MonoBehaviour {
public float density = 1f;
public bool recalculateOnAwake = true;
Rigidbody rb;
@skaslev
skaslev / quasicrystal.py
Created March 15, 2016 13:01 — forked from omegahm/quasicrystal.py
Quasicrystals in Python
# -*- coding: utf-8 -*-
import bohrium as np
from math import pi
import matplotlib.pyplot as plt
import matplotlib.colors as colors
fig = plt.figure()
plt.xticks([])
plt.yticks([])
@skaslev
skaslev / sudo.py
Created April 15, 2016 09:00 — forked from barneygale/sudo.py
import sys, marshal, functools, subprocess
child_script = """
import marshal, sys, types;
fn, args, kwargs = marshal.load(sys.stdin)
marshal.dump(
types.FunctionType(fn, globals())(*args, **kwargs),
sys.stdout)
"""
@skaslev
skaslev / pg-pong.py
Created June 29, 2016 16:14 — forked from karpathy/pg-pong.py
Training a Neural Network ATARI Pong agent with Policy Gradients from raw pixels
""" Trains an agent with (stochastic) Policy Gradients on Pong. Uses OpenAI Gym. """
import numpy as np
import cPickle as pickle
import gym
# hyperparameters
H = 200 # number of hidden layer neurons
batch_size = 10 # every how many episodes to do a param update?
learning_rate = 1e-4
gamma = 0.99 # discount factor for reward
@skaslev
skaslev / after.agda
Created July 28, 2016 05:56 — forked from mbrcknl/after.agda
Code from BFPG talk about dependent types in Agda
-- Matthew Brecknell @mbrcknl
-- BFPG.org, March-April 2015
-- With thanks to Conor McBride (@pigworker) for his lecture series:
-- https://www.youtube.com/playlist?list=PL44F162A8B8CB7C87
-- from which I learned most of what I know about Agda, and
-- from which I stole several ideas for this talk.
open import Agda.Primitive using (_⊔_)
@skaslev
skaslev / pearcy.py
Created September 14, 2016 12:22 — forked from anonymous/pearcy.py
Compute and plot Pearcey integral
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as integrate
# Dimension of image in pixels
N = 256
# Number of samples to use for integration
M = 32
@skaslev
skaslev / NatInd.idr
Created September 18, 2016 19:45 — forked from david-christiansen/NatInd.idr
Simple proof automation with reflected elaboration
module NatInd
import Language.Reflection.Elab
import Language.Reflection.Utils
%default total
trivial : Elab ()
trivial = do compute
g <- snd <$> getGoal
@skaslev
skaslev / 0 README.md
Created January 13, 2017 12:08 — forked from chriseth/0 README.md
Formal verification for re-entrant Solidity contracts

This gist shows how formal conditions of Solidity smart contracts can be automatically verified even in the presence of potential re-entrant calls from other contracts.

Solidity already supports formal verification of some contracts that do not make calls to other contracts. This of course excludes any contract that transfers Ether or tokens.

The Solidity contract below models a crude crowdfunding contract that can hold Ether and some person can withdraw Ether according to their shares. It is missing the actual access control, but the point that wants to be made

-- Return the maximum unsigned number of a given width.
def max_unsigned : ℕ → ℕ
| 0 := 0
| (nat.succ x) := 2 * max_unsigned x + 1
open tactic nat
/- Function for convertiong a nat into a Lean expression using nat.zero and nat.succ.
Remark: the standard library already contains a tactic for converting nat into a binary encoding. -/
meta def nat.to_unary_expr : nat → tactic expr
meta def blast : tactic unit := using_smt $ return ()
structure Category :=
(Obj : Type)
(Hom : Obj → Obj → Type)
structure Functor (C : Category) (D : Category) :=
(onObjects : C^.Obj → D^.Obj)
(onMorphisms : Π { X Y : C^.Obj },
C^.Hom X Y → D^.Hom (onObjects X) (onObjects Y))