Skip to content

Instantly share code, notes, and snippets.

View paulyoung's full-sized avatar
💭
Type check and prove things

Paul Young paulyoung

💭
Type check and prove things
View GitHub Profile
@gelisam
gelisam / StringPattern.hs
Created January 30, 2020 14:39
A Haskell reimplementation of Scala's "direct pattern-matching on strings"
-- in response to https://twitter.com/chrislpenner/status/1221784005156036608
--
-- The goal is to mimic this Scala code, but in Haskell:
--
-- > "spotify:user:123:playlist:456" match {
-- > case s"spotify:user:$userId:playlist:$playlistId"
-- > => ($userId, $playlistId) // ("123", "456")
-- > }
{-# LANGUAGE DeriveFunctor, LambdaCase, PatternSynonyms, QuasiQuotes, RankNTypes, TemplateHaskell, TypeOperators, ViewPatterns #-}
{-# OPTIONS -Wno-name-shadowing #-}
@ChrisPenner
ChrisPenner / Optics Cheatsheet.md
Last active April 21, 2025 12:45
Optics Cheatsheet
@jimmychu0807
jimmychu0807 / string-conversion.rs
Created November 21, 2019 10:20
Conversion between String, str, Vec<u8>, Vec<char> in Rust
use std::str;
fn main() {
// -- FROM: vec of chars --
let src1: Vec<char> = vec!['j','{','"','i','m','m','y','"','}'];
// to String
let string1: String = src1.iter().collect::<String>();
// to str
let str1: &str = &src1.iter().collect::<String>();
// to vec of byte
@chrisdone
chrisdone / Intro.md
Last active May 20, 2024 12:44
Statically checked overloaded strings

Statically checked overloaded strings

This gist demonstrates a trick I came up with which is defining IsString for Q (TExp a), where a is lift-able. This allows you to write $$("...") and have the string parsed at compile-time.

On GHC 9, you are able to write $$"..." instead.

This offers a light-weight way to enforce compile-time constraints. It's basically OverloadedStrings with static checks. The inferred return type

@stuartlangridge
stuartlangridge / example.js
Last active March 4, 2024 19:04
Exporting an SVG from Figma and identifying which SVG elements in the exported file correspond to which objects in Figma
const getSvgNamesForNodes = () => {
// this is guesswork. When Figma has two nodes with the same name (say, "Union"),
// it serialises them into SVG with names "Union" and "Union_2", but it's not
// clear which one becomes "Union" and which "Union_2". It is theorised that this
// is done in the same order that .findAll returns, so we make use of that.
// Figma might decide to change this at any time, of course. It would be much
// nicer if there were an SVG export option which also serialised getPluginData()
// data as data-* attributes in the output SVG, but there isn't, yet.
let names = {};
let nameIndices = {};
@bodil
bodil / init.ts
Created August 12, 2019 17:34
Snapshot of my vscode-use-package setup
import * as vscode from "vscode";
import { initUsePackage, usePackage, configSet } from "vscode-use-package";
import * as nav from "./nav";
import * as js from "./js";
import * as rust from "./rust";
export function init(context: vscode.ExtensionContext) {
console.log(`HELLO FROM INIT SCRIPT`);
@paf31
paf31 / ToPursTyConPoly.hs
Last active April 8, 2020 07:08
ToPursTyConPoly
{-# language TypeInType #-}
-- | Types which have PureScript equivalents
class ToPursTyCon a where
toPursTyCon :: Tagged a PursTypeConstructor
-- | The default instance uses 'G.Generic' and pattern matches on the
-- type's representation to create a PureScript type.
default toPursTyCon :: (G.Generic a, GenericToPursTyCon (G.Rep a)) => Tagged a PursTypeConstructor
toPursTyCon = retag $ genericToPursTyConWith @(G.Rep a) defaultPursTypeOptions
let UserContext = React.createContext();
class App extends React.Component {
state = {
user: null,
setUser: user => {
this.setState({ user });
}
};
SSE3=1 SSSE3=1 SSE4_1=1 SAHF=1 AVX=1 FMA3=1 BMI1=1 BMI2=1 LZCNT=1 POPCNT=1 ATOM=0
Synopsis:
shell [options] [--shell] [<file>...]
d8 [options] [-e <string>] [--shell] [[--module] <file>...]
-e execute a string in V8
--shell run an interactive JavaScript shell
--module execute a file as a JavaScript module
Options:
@coin8086
coin8086 / using-proxy-for-git-or-github.md
Last active January 24, 2025 07:47
Use Proxy for Git/GitHub

Use Proxy for Git/GitHub

Generally, the Git proxy configuration depends on the Git Server Protocol you use. And there're two common protocols: SSH and HTTP/HTTPS. Both require a proxy setup already. In the following, I assume a SOCKS5 proxy set up on localhost:1080. But it can also be a HTTP proxy. I'll talk about how to set up a SOCKS5 proxy later.

SSH Protocol

When you do git clone ssh://[user@]server/project.git or git clone [user@]server:project.git, you're using the SSH protocol. You need to configurate your SSH client to use a proxy. Add the following to your SSH config file, say ~/.ssh/config:

ProxyCommand nc -x localhost:1080 %h %p