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
@Centril
Centril / scoped_parent.rs
Created February 20, 2015 06:43
Rust: scoped, accessing parent thread
use std::thread::{self, JoinGuard};
use std::option::Option;
use std::marker::Send;
fn callback(v: usize) -> usize { v * 2 }
type CB = Fn(usize) -> usize + Sync + Send;
type Callback = Box<CB>;
struct S<'a> {
@Centril
Centril / box_callback.rs
Last active May 17, 2017 15:05
Rust: Sending callbacks in struct to a scoped thread with Box
#![feature(core)]
#![feature(std_misc)]
use std::thread::{Thread, JoinGuard};
fn callback(v: usize) -> usize { v * 2 }
struct S {
cb: Box<Fn(usize) -> usize + Send>,
}
@Centril
Centril / _.objectMap.js
Created October 30, 2014 04:24
lodash: _.objectMap
/**
* Creates an object where each property is composed from
* an element of keys (key) and the value from callback(key).
*
* @param {array} keys The array of keys.
* @param {function} [callback=_.identity] The callback(key) that returns the object:s values.
* @return {object} Returns an object composed of the given keys and callback(key) for values.
*/
_.objectMap = function(keys, callback) {
callback = callback || _.identity;