Skip to content

Instantly share code, notes, and snippets.

:octocat:
Working from home

Guilherme Kunigami kunigami

:octocat:
Working from home
Block or report user

Report or block kunigami

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View iterator.js
function makeIterator(n) {
return {
cnt: n,
next: function() {
this.cnt--;
return {value: this.cnt, done: this.cnt < 0};
},
[Symbol.iterator]: function() { return this }
View async.js
try {
a = await fetchSomeStuff();
b = await fetchSomeStuffDependingOnA(a);
c = await fetchSomeStuffDependingOnB(b);
} catch (ex) {
handleException(ex);
}
View fetchSomeStuff.js
function fetchSomeStuff() {
return new Promise((resolve, reject) => {
someAsyncRequest()
.onSuccess(
payload => resolve(payload.value)
)
.onFailure(
payload => reject(payload.error)
)
.execute();
View promises.js
fetchSomeStuff().then(
function (a) {
return fetchSomeStuffDependingOnA(a);
}
).then(
function (b) {
return fetchSomeStuffDependingOnB(b);
}
).then(
function (c) {
View callback_hell.js
fetchSomeStuff(
/* onSuccess*/ function (a) {
fetchSomeStuffDependingOnA(
a,
/* onSuccess */ function (b) {
fetchSomeStuffDependingOnB(
b,
/* onSuccess */ function (c) {
/* Code goes on here */
},
View closure.rs
fn find_node_with_visitor<F>(
...
k: &K,
mut visitor: F
) -> where F: FnMut(&K) {
...
visitor(&key);
...
}
View node_ptr.rs
struct NodePtr<K: Ord, V>(*mut RBTreeNode<K, V>);
...
pub struct RBTree<K: Ord, V> {
root: NodePtr<K, V>,
...
}
...
// in find_node_with_visitor()
let mut temp = &self.root;
let key = &(*temp.0).key;
View unsafe.rs
let mut num = 5;
let r1 = &num as *const i32;
unsafe {
println!("r1 is: {}", *r1);
}
View wrap_search.rs
// Every container key is smaller than the target_key. In this case we 'wrap around' the
// table and select the first element.
if (closest_key == std::u32::MAX) {
let result = self.containers.get_first();
match result {
None => {
return Err("Did not find first entry.");
}
Some((_, entry)) => {
let container_id = &entry.id;
View find_node.rs
fn find_node_with_visitor<F>(
&self,
k: &K,
mut visitor: F
) -> NodePtr<K, V> where F: FnMut(&K) {
if self.root.is_null() {
return NodePtr::null();
}
let mut temp = &self.root;
unsafe {
You can’t perform that action at this time.