Skip to content

Instantly share code, notes, and snippets.

View kejace's full-sized avatar

Kristoffer Josefsson kejace

  • NYC / LA and in between
  • X @kejace
View GitHub Profile
@NicolasT
NicolasT / Primes.hs
Created August 1, 2011 14:14
Simple Haskell implementation of the Paillier homomorphic encryption scheme
{-# LANGUAGE BangPatterns, ScopedTypeVariables #-}
-- Stuff taken from the RSA module for now
module Primes where
import Data.Bits
import Data.Int
import Data.Word
import Data.ByteString.Lazy (ByteString)
@edouardp
edouardp / radiance_writer.py
Created July 11, 2012 10:47
Numpy based writer for Radiance HDR files
# Assumes you have a np.array((height,width,3), dtype=float) as your HDR image
import numpy as np
f = open("xxx.hdr", "wb")
f.write("#?RADIANCE\n# Made with Python & Numpy\nFORMAT=32-bit_rle_rgbe\n\n")
f.write("-Y {0} +X {1}\n".format(image.shape[0], image.shape[1]))
brightest = np.maximum(np.maximum(image[...,0], image[...,1]), image[...,2])
mantissa = np.zeros_like(brightest)
@stonegao
stonegao / crdt.md
Created September 4, 2013 10:02 — forked from pozorvlak/crdt.md

CvRDTs are as general as they can be

What are you talking about, and why should I care?

Now that we live in the Big Data, Web 3.14159 era, lots of people want to build databases that are too big to fit on a single machine. But there's a problem in the form of the CAP theorem, which states that if your network ever partitions (a machine goes down, or part of the network loses its connection to the rest) then you can keep consistency (all machines return the same answer to

@agocorona
agocorona / cordova.hs
Last active September 25, 2015 16:31
--
-- Hello-World of the cordova/phonegap application using Haskell.
--
-- here is the screenshoot
--
-- https://twitter.com/AGoCorona/status/532948528621178880
--
-- So that Haste-Haskell can be used to create hybrid smartphone applications
--
-- The original cordova JavaScript hello world is installed following the instructions of this page
@edsko
edsko / DependentServant.hs
Last active July 2, 2020 06:52
See "Dependently typed servers in Servant" (http://www.well-typed.com/blog/2015/12/dependently-typed-servers/) for the blog post accompanying this gist.
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
@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.

@chriseth
chriseth / async.md
Last active December 26, 2023 09:13
Async Solidity Contracts

Having seen @pirapira's sketch of Bamboo ( https://github.com/pirapira/bamboo/ ), which proposed to add better control about the "smart contract program flow", even across calls, I thought that this should certainly be added to Solidity, and actually, it might even be possible now to a certain degree using inline assembly.

The problem is that with many functions in a contract, it is not always clear which can be called at which stage in the contract's lifetime. Certain smart contracts would be easier to understand if written as follows:

@mtesseract
mtesseract / haskell-records.md
Last active March 8, 2023 22:25
Working around Haskell's namespace problem for records

The Problem

Defining records in Haskell causes accessor functions for the record's fields to be defined. There is no seperate namespace for these accessor functions.

The Goal

Be able to

  • use records in Haskell, which share field names.
  • use lenses for accessing these fields
@alexvandesande
alexvandesande / ethernalsale.js
Last active October 21, 2021 04:40
This is a first draft at what could be a continuous token sale. I just wrote it and haven't tested it but it shows the proof of concept: tokens are continuously generated in any curve desired and sold for the highest bidder. Since there's a maximum token sale speed, this guarantees that sales can't end too quickly. Since the sale always starts f…
pragma solidity ^0.4.2;
contract ethernalSale {
struct order {
uint amount;
address buyer;
}
mapping (uint => order) orderBook;
mapping (address => uint) balanceOf;
@danoneata
danoneata / Sudoku.hs
Last active August 20, 2022 01:27
Applicative-based Sudoku solver
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Control.Applicative
import Data.Char
import Data.List (intersperse)
import Data.Monoid hiding (All, Any)
import Data.Foldable hiding (all, any)
import Prelude hiding (all, any)