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-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,
@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",
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

@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;
// This test enumerates various cases of interest for partial
// [re]initialization of ADTs and tuples.
//
// See rust-lang/rust#21232, rust-lang/rust#54986, and rust-lang/rust#54987.
//
// All of tests in this file are expected to change from being
// rejected, at least under NLL (by rust-lang/rust#54986) to being
// **accepted** when rust-lang/rust#54987 is implemented.
// (That's why there are assertions in the code.)
//
trait App<Input>
where
Input: { request: http::Request }
{
type Output: Into<http::Response>;
fn call(self, input: Input) -> Self::Output;
}
struct AuthApp<T> {

Proposal:

Add setjmp and longjmp with the following semantics:

pub type JmpBuf = <implementation-defined>;

/// Saves the current execution context into `env`. If `longjmp(env, val)` is used 
/// to restore execution at this call site, this function returns `val`. Otherwise, 
/// it returns `0`. 

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: