Skip to content

Instantly share code, notes, and snippets.

@edmundsmith
edmundsmith / writeup.md
Created July 7, 2019 20:47
Method for Emulating Higher-Kinded Types in Rust

Method for Emulating Higher-Kinded Types in Rust

Intro

I've been fiddling about with an idea lately, looking at how higher-kinded types can be represented in such a way that we can reason with them in Rust here and now, without having to wait a couple years for what would be a significant change to the language and compiler.

There have been multiple discussions on introducing higher-ranked polymorphism into Rust, using Haskell-style Higher-Kinded Types (HKTs) or Scala-looking Generalised Associated Types (GATs). The benefit of higher-ranked polymorphism is to allow higher-level, richer abstractions and pattern expression than just the rank-1 polymorphism we have today.

As an example, currently we can express this type:

@arasmussen
arasmussen / CannySDK.js
Created April 4, 2019 15:00
React example of the widget embed
const CannySDK = {
init: () => {
(function(w, d, i, s) {
if (typeof w.Canny === 'function') {
return;
}
var c = function(){
c.q.push(arguments);
};
@t184256
t184256 / getable_woes.rs
Created July 24, 2018 17:37
Getable woes
#[macro_use]
extern crate gluon_codegen;
extern crate gluon;
#[macro_use]
extern crate gluon_vm;
use gluon::vm::{self, ExternModule};
use gluon::{import, Compiler, Thread};
use gluon::{import::Import, RootedThread};
@dwhitney
dwhitney / README.md
Last active May 17, 2024 09:25
Quick React Native with PureScript
  1. create-react-native-app purescript-app; cd purescript-app

  2. pulp init --force

  3. pulp build

  4. src/Main.js

var React = require("react");
var RN = require("react-native");

exports.text = function(props){
@steven2358
steven2358 / ffmpeg.md
Last active July 2, 2025 17:10
FFmpeg cheat sheet
@Rahix
Rahix / 01-rust-thread-affinity.md
Last active February 2, 2025 13:13
Rust demonstration of setting thread affinity with pthread_setaffinity_np

Call this program with -s N to set a specific CPU. Without -s, the thread will have the default affinity.

This program will print out the main threads CPU, the child threads CPU and the child threads affinity after optionally setting it.

@lanedraex
lanedraex / listener.rs
Created November 5, 2017 09:12
Rust UDP socket: send and receive
use std::net;
use std::env;
fn listen(socket: &net::UdpSocket, mut buffer: &mut [u8]) -> usize {
let (number_of_bytes, src_addr) = socket.recv_from(&mut buffer).expect("no data received");
println!("{:?}", number_of_bytes);
println!("{:?}", src_addr);
anonymous
anonymous / playground.rs
Created September 7, 2017 22:31
Rust code shared from the playground
extern crate clap;
use clap::{App,Arg};
fn main() {
let m = App::new("My Program")
.arg(
Arg::with_name("demo").short("d")
)
.arg(
Arg::with_name("rest")
@LukasKalbertodt
LukasKalbertodt / 0-rust-wasm-llvm-backend.md
Last active September 22, 2020 12:18
Several Rust & WebAssembly notes

Compiling Rust to Wasm manually with the LLVM wasm-backend (without Emscripten)

EDIT November 2017: recently the target wasm32-unknown-unknown was added to rustc which uses the LLVM WASM backend and works without Emscripten. This is now the recommended way of generating WASM code from Rust (as it is much easier). Thus, this gist document is pretty much useless now. A great resource on getting started with WASM and Rust is hellorust.com: Setup and Minimal Example.




anonymous
anonymous / playground.rs
Created June 19, 2017 06:34
Shared via Rust Playground
use std::cell::UnsafeCell;
use std::ops::*;
use std::marker::PhantomData;
pub struct DefaultTag {}
pub struct SyncCell<'cc, T> {
unsafe_cell: UnsafeCell<T>,
phantom_borrow_creator: PhantomData<&'cc ()>,
}