Applied to jQuery 1.7 dev. This was just an idea i made long ago, dumping for keepsake.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(alloc, heap_api)] | |
extern crate alloc; | |
use std::rc::Rc; | |
use std::mem::{align_of, align_of_val, size_of, size_of_val}; | |
fn to_rc<T: ?Sized>(b: Box<T>) -> Rc<T> { | |
// super duper undefined behavior! | |
struct InnerRcBox<T: ?Sized> { | |
strong: usize, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(try_from)] | |
use std::str::FromStr; | |
use std::convert::TryFrom; | |
macro_rules! str_to_enum { | |
($typ: path, $($var: ident),+) => { | |
impl std::str::FromStr for $typ { | |
type Err = (); | |
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For debugging purposes: | |
impl<I, O, E=u32> IResult<I, O, E> { | |
fn map_rem<R, F: FnOnce(I) -> R>(self, f: F) -> IResult<R, O, E> { | |
use IResult::*; | |
match s { | |
Done(i, o) => Done(f(i), o), | |
Error(e) => Error(e), | |
Incomplete(n) => Incomplete(n), | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::sync::{Arc, Mutex, MutexGuard, LockResult, PoisonError}; | |
pub enum OptArcMutex<T> { | |
Arc(Arc<Mutex<T>>), | |
Imm(T) | |
} | |
pub enum MGuard<'a, T: 'a> { | |
Real(MutexGuard<'a, T>), | |
Fake(&'a mut T) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(asm)] | |
#[inline(never)] | |
fn noop() { | |
unsafe { | |
asm!("NOP"); | |
} | |
} | |
struct S { x: usize } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Foldable (foldl') | |
import Data.List (genericReplicate) | |
distribute2 :: Integral a => a -> a -> [a] | |
distribute2 sum nBuckets = | |
let distHelp nBuckets (remains, tables) i = | |
let tablesLeft = nBuckets - i | |
currBucket = (remains + tablesLeft - 1) `div` tablesLeft | |
in (remains - currBucket, tables ++ [currBucket]) | |
in snd $ foldl' (distHelp nBuckets) (sum, []) [0..nBuckets - 1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface SearchResult<T> { | |
T getResult(); | |
double getRelevance(); | |
// Just for being able to "clone" with other relevance... | |
SearchResult<? extends T> withRelevance( double relevance ); | |
} | |
interface SearchCriteria<T> { | |
SearchResult<? extends T> apply( SearchResult<? extends T> result ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List.metaClass.foldn = { init, closure -> | |
def l = delegate.clone() | |
def acc = init | |
def it = l.listIterator() | |
while ( it.hasNext() ) { | |
def e = it.next() | |
it.remove() | |
closure( acc, e, it ) | |
} | |
return acc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dumping old code as gists... | |
(function($) { | |
$.mouseMovement = { | |
stack: [], | |
clearInterval: 1000 | |
}; | |
var stack = $.mouseMovement.stack; |