Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE TupleSections #-}
import Control.Monad.State (State, evalState, get, gets, modify, put)
import Data.Function (on)
import Data.List (unionBy)
import Data.Map (Map)
import Data.Maybe (fromMaybe)
import qualified Data.Map as Map
@Garciat
Garciat / fireworks.html
Last active January 31, 2025 23:21
Fireworks // Draws very simple random particle-based fireworks on the screen.
<!DOCTYPE html>
<html>
<head>
<title>Fireworks</title>
<style>html,body{margin:0;height:100%;}</style>
</head>
<body>
<script defer>
const SCRW = document.body.clientWidth;
const SCRH = document.body.clientHeight;
@Garciat
Garciat / fibo.py
Last active January 20, 2018 15:05
class Vec2(object):
def __init__(self, x, y):
self.x = x
self.y = y
def dot(v, w):
return v.x * w.x + v.y * w.y
class Mat22(object):
def __init__(self, a, b, c, d):
@Garciat
Garciat / ondulator.html
Last active January 31, 2025 23:23
Ondulator // Simulates a hypnotizing animation I saw once, somewhere. Click to change the pattern.
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ondulator</title>
<style>html,body{margin:0;height:100%;}</style>
<script>
import Data.SBV
fruits :: SInteger -> SInteger -> SInteger -> SBool
fruits a b c = equation &&& positive
where
x = sFromIntegral a :: SReal
y = sFromIntegral b :: SReal
z = sFromIntegral c :: SReal
equation = x / (y + z) + y / (x + z) + z / (x + y) .== 4
@Garciat
Garciat / Circle.hs
Last active September 14, 2017 22:44
import Control.Monad
import Math.NumberTheory.Logarithms (integerLog2)
simulate :: Integer -> Integer
simulate n = head (go [1..n])
where
go [x] = [x]
go (x1:x2:xs) = go (xs ++ [x1])
def out_of_process(func):
from types import GeneratorType
GENERATOR = b'#GENERATOR#'
DONE = b'#DONE#'
def runner(conn, *args, **kwargs):
return_value = func(*args, **kwargs)
if isinstance(return_value, GeneratorType):
conn.send(GENERATOR)
for val in return_value:
#include <type_traits>
template <typename T>
struct wrap;
template <typename T>
constexpr auto is_wrap_v = false;
template <typename T>
constexpr auto is_wrap_v<wrap<T>> = true;
import com.sun.jna.Library;
import com.sun.jna.Native;
import com.sun.jna.Pointer;
import sun.misc.Unsafe;
import java.lang.reflect.Field;
public class Program {
private static final Unsafe UNSAFE;
#include <utility>
#include <type_traits>
template<typename T>
struct identity { using type = T; };
template<std::size_t I, typename... Ts>
struct nth_type;
template<typename T, typename... Ts>