Skip to content

Instantly share code, notes, and snippets.

View lancelet's full-sized avatar
🖖
Reconfiguring the Primary Power Coupling

Jonathan Merritt lancelet

🖖
Reconfiguring the Primary Power Coupling
View GitHub Profile
@lancelet
lancelet / wgpu_context.rs
Created January 7, 2025 07:53
wgpu + WASM + winit
//! Creates WGPU context that must run async.
//!
//! Three important parts of the WGPU API are async functions:
//! - Creating a new WGPU Instance.
//! - Requesting a new WGPU Adapter.
//! - Creating a WGPU Device and Queue.
//!
//! In non-web applications, we would like to block on these functions. However,
//! for WASM (web) usage, we cannot block.
//!
@lancelet
lancelet / bartosz-nerd-snipe.hs
Created January 26, 2021 05:44
The "No Monty" problem (posed by Bartosz Milweski)
#!/usr/bin/env cabal
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{- cabal:
build-depends:
base
@lancelet
lancelet / format.hs
Last active May 16, 2021 09:44
Ormolu + cabal-fmt formatter and checker
#!/usr/bin/env cabal
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{- cabal:
ghc-options:
-O2 -threaded -rtsopts "-with-rtsopts=-N -T"
-Wall -Wcompat -Wincomplete-record-updates
-Wincomplete-uni-patterns -Wredundant-constraints
@lancelet
lancelet / utah-teapot.py
Created September 27, 2020 03:42
Attempt at a Utah Teapot loader
# Crappy Utah Teapot loader script for Blender 2.90.1
import bpy
from mathutils import Vector
def create4x4patch(points):
surface_data = bpy.data.curves.new('wook', 'SURFACE')
surface_data.dimensions = '3D'
# set points per segments (U * V)
@lancelet
lancelet / macos-haskell-run-vulkan-triangles.sh
Created July 8, 2019 10:11
Build and run the Haskell vulkan-triangles example on MacOS.
#!/usr/bin/env bash
#
# File: macos-haskell-run-vulkan-triangles.sh
#
# Haskell Vulkan on MacOS example:
# Build and run the vulkan-triangles GLFW example.
#
# The purpose of this script is to automate building and running the
# vulkan-triangles GLFW example. There are some half-baked instructions
# for MacOS available here:
@lancelet
lancelet / candy.hs
Created November 24, 2018 06:32
FP vs OO; A Better Way to Count Candy
#!/usr/bin/env stack
{- stack
script
--resolver lts-12.19
--package containers
--package double-conversion
--package text
--package text-show
-}
{-
@lancelet
lancelet / Main.hs
Created December 26, 2017 02:14
OpenCL + Vector + Kernel Quasiquoting
{-# LANGUAGE QuasiQuotes #-}
module Main where
import Control.Parallel.OpenCL
import Data.Vector.Storable (Vector)
import qualified Data.Vector.Storable as V
import Data.Vector.Storable.Mutable (IOVector)
import qualified Data.Vector.Storable.Mutable as MV
import Foreign (castPtr, nullPtr, sizeOf)
import Foreign.C.Types (CFloat)
@lancelet
lancelet / rk4.hs
Last active October 31, 2017 06:13
Runge-Kutta integration of some equations in Haskell
#! /usr/bin/env nix-shell
#! nix-shell -i runghc -p 'ghc.withPackages (ps: [ ps.hmatrix ])'
import Numeric.LinearAlgebra
-- | Represents the coupled ODEs (Example (1)):
--
-- y[0] = position = p
-- y[1] = velocity = v
--
@lancelet
lancelet / WillBeTrue.scala
Created March 2, 2016 10:09
WillBeTrue (Improved)
// Intended to be run in shapeless sbt console; use :paste
//--- paste this first to define the macro
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
import scala.util.control.NonFatal
object WillBeTrue {
@lancelet
lancelet / WillBeTrue.scala
Last active March 2, 2016 10:19
WillBeTrue
// (This is an older version of the Gist here: https://gist.github.com/lancelet/0d0713af7eb1401c9b1a)
// (Only hanging around because I posted it to a Gitter group.)
// Intended to be run in shapeless current master sbt console; use :paste
//--- paste this first to define the macro
import scala.language.experimental.macros
import scala.reflect.macros.whitebox
import scala.util.control.NonFatal