Skip to content

Instantly share code, notes, and snippets.

View Centril's full-sized avatar
🏠
Working from home

Mazdak Farrokhzad Centril

🏠
Working from home
  • Sweden
View GitHub Profile
@Noitidart
Noitidart / _ff-addon-snippet-CUISnips.js
Last active August 30, 2015 20:16
_ff-addon-snippet-CUISnips - Snippets of CustomizableUI.jsm used in Fiefox code.
id: "edit-controls",
type: "custom",
defaultArea: CustomizableUI.AREA_PANEL,
onBuild: function(aDocument) {
let buttons = [{
id: "cut-button",
command: "cmd_cut",
label: true,
tooltiptext: "tooltiptext2",
shortcutId: "key_cut",
@14427
14427 / hkt.rs
Last active February 7, 2024 10:18
Higher-kinded type trait
use std::rc::Rc;
trait HKT<U> {
type C; // Current type
type T; // Type with C swapped with U
}
macro_rules! derive_hkt {
($t:ident) => {
impl<T, U> HKT<U> for $t<T> {
@Noitidart
Noitidart / _ff-addon-snippet-WinApi_removeMinMaxBtns.js
Created August 24, 2015 09:08
_ff-addon-snippet-WinApi_removeMinMaxBtns - On Windows this removes the minimize and maximize button of the targeted window. [jsctypes] [winapi]
Cu.import('resource://gre/modules/ctypes.jsm');
var is64bit = ctypes.voidptr_t.size == 4 ? false : true;
var ifdef_UNICODE = true;
var TYPES = {
ABI: is64bit ? ctypes.default_abi : ctypes.winapi_abi,
CALLBACK_ABI: is64bit ? ctypes.default_abi : ctypes.stdcall_cabi,
BOOL: ctypes.bool,
anonymous
anonymous / playground.rs
Created September 17, 2016 23:40
Shared via Rust Playground
trait ShortCircuit {
fn short(&self) ->
}
trait And<Rhs=Self> {
type Output;
fn short(&self) -> Option<Self::Output>;
fn and(self, rhs: Rhs) -> Self::Output;
}
@insaneinside
insaneinside / draft.markdown
Created September 13, 2017 01:22
Whole-Crate Test-Case Reduction with C-Reduce

Whole-Crate Test-Case Reduction with C-Reduce

Sometimes, when working on a complex piece of software — or even a simple program or library with a non-trivial number of moving parts — you run into an issue and have absolutely no idea how to reduce your code to the minimum necessary in order to reproduce the error.

For the past several months I've been blocked by some trait-resolution errors in Symtern, my general-purpose interner crate. I knew the errors were somehow related to

@withoutboats
withoutboats / constraint-kinds.md
Last active January 9, 2023 17:14
Constraint Kinds in Rust

Notes on adding Constraint Kinds to Rust

Background: Constraint Kinds

a trait can be thought of as a type operator generating a "constraint" - what in Rust would usually be called a bound. For example:

// Declares a new item `Foo` with kind `type -> constraint`
trait Foo { }

impl Trait is Always Existential

Recently, Rust 1.26 was released, and with it came stable access to a heavily desired feature: impl Trait. For those unfamiliar, impl Trait lets you write something like this:

fn foo<'a, A, B>(x: &'a mut A) -> impl Bar<'a, B> { ... }

and have it be translated to something like this:

@varkor
varkor / traits-as-type-constructors.md
Created August 28, 2018 14:58
A categorical model of traits in Rust

Traits as type constructors

This is a demonstration that we may view traits as type constructors: that is, functions from Type to Type. This view is motivated from a categorical perspective of type theory, in which the morphisms of the category take the central role. Cf. subobjects, which are represented by morphisms, rather than objects in a different category.

I'm assuming that the category of types, Type, is bicartesian closed. The set of morphisms between any two objects includes the set of functions denoted by Fn, FnMut and FnOnce in Rust.

@rust-play
rust-play / playground.rs
Created August 29, 2018 23:51
Code shared from the Rust Playground
use std::ops::Index;
struct Example<T: 'static>(&'static [T]);
impl<F, I, T> Index<F> for Example<T>
where
F: FnOnce(usize) -> I,
[T]: Index<I>
{
type Output = <[T] as Index<I>>::Output;
@rust-play
rust-play / playground.rs
Created August 30, 2018 00:21
Code shared from the Rust Playground
#![feature(unboxed_closures)]
#![feature(fn_traits)]
use std::marker::PhantomData;
use std::ops::{Add, FnOnce};
struct WhateverFn<F, T>(F, PhantomData<T>);
impl<F, T> FnOnce<(T,)> for WhateverFn<F, T> where F: FnOnce<(T,)> {
type Output = F::Output;