Skip to content

Instantly share code, notes, and snippets.

View thautwarm's full-sized avatar
🧐

Taine Zhao thautwarm

🧐
View GitHub Profile
@arctangent
arctangent / hmazed.hs
Created December 29, 2011 10:00
Maze generator in Haskell
-- Simple maze generator in Haskell
-- Jacob Conrad Martin
-- http://jacobconradmartin.com
import System.Random
import Debug.Trace
import Control.Monad.State
data Location = Location { x::Int, y::Int } deriving (Eq)
data Path = Path { from::Location, to::Location } deriving (Eq)
@kseo
kseo / recon.ml
Last active March 28, 2024 14:41
A Hindley-Milner type inference implementation in OCaml
#! /usr/bin/env ocamlscript
Ocaml.ocamlflags := ["-thread"];
Ocaml.packs := [ "core" ]
--
open Core.Std
type term =
| Ident of string
| Lambda of string * term
| Apply of term * term
@delimitry
delimitry / python_hashes.py
Last active September 24, 2020 11:47
Python hash algorithms
#!/usr/bin/evn python
# -*- coding: utf-8 -*-
import sys
import math
import struct
if sys.version_info > (3, 0):
basestring_type = str
else:
@delimitry
delimitry / uint_7bit.py
Last active November 7, 2022 16:09
Python version of unsigned integer 7-bit encoder and decoder
#!/usr/bin/evn python
# -*- coding: utf8 -*-
def encode_to_7bit(value):
"""
Encode unsigned int to 7-bit str data
"""
data = []
number = abs(value)
while number >= 0x80:
@ertseyhan
ertseyhan / remount.sh
Created February 2, 2016 20:51
Temporarily increase size of tmp folder on Arch linux
#!/bin/bash
sudo mount -o remount,size=10G,noatime /tmp
echo "Done. Please use 'df -h' to make sure folder size is increased."
@JamesPHoughton
JamesPHoughton / make_python_identifier.py
Last active February 28, 2024 01:40
Converts an arbitrary string into something that can be used as a python identifier. Checks for namespace conflicts and conflicts with python and specified reserved words.
def make_python_identifier(string, namespace=None, reserved_words=None,
convert='drop', handle='force'):
"""
Takes an arbitrary string and creates a valid Python identifier.
If the python identifier created is already in the namespace,
or if the identifier is a reserved word in the reserved_words
list, or is a python default reserved word,
adds _1, or if _1 is in the namespace, _2, etc.
Parameters
@eevee
eevee / perlin.py
Last active March 2, 2024 08:48
Perlin noise in Python
"""Perlin noise implementation."""
# Licensed under ISC
from itertools import product
import math
import random
def smoothstep(t):
"""Smooth curve with a zero derivative at 0 and 1, making it useful for
interpolating.
@Icelandjack
Icelandjack / Constraints.org
Last active April 2, 2024 20:22
Type Classes and Constraints

Reddit discussion.

Disclaimer 1: Type classes are great but they are not the right tool for every job. Enjoy some balance and balance to your balance.

Disclaimer 2: I should tidy this up but probably won’t.

Disclaimer 3: Yeah called it, better to be realistic.

Type classes are a language of their own, this is an attempt to document features and give a name to them.

@svaksha
svaksha / pythontojulia.md
Created May 12, 2017 12:27 — forked from cuckookernel/pythontojulia.md
Python to Julia Quick translation / conversion reference Guide

A quick and dirty syntax translation / conversion reference guide to ease the transition between Python and Julia. This is not meant as a reference to the language. For that you should read the manual.

Some important differences

  • Arrays in Julia are indexed starting from 1.
  • In Julia classes (i.e. types) don't own methods. Methods are implementations of generic functions and are invoked in a "static style", i.e. instead of Python's str1.rstrip(), we will have rstrip( str1 ), instead of file1.close(), close( file1 ).

Some important similarities.

@yasirkula
yasirkula / EditorCollapseAll.cs
Last active March 11, 2024 11:53
An editor script for Unity 3D to collapse all GameObject's in Hierarchy view or to collapse all folders in Project view. See the comments section below for instructions.
using System.Collections.Generic;
using System.Reflection;
using UnityEditor;
using UnityEditor.IMGUI.Controls;
using UnityEditorInternal;
using UnityEngine.SceneManagement;
public static class EditorCollapseAll
{
private const BindingFlags INSTANCE_FLAGS = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance;