This file contains hidden or 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
#!/bin/bash | |
sum() { | |
local result=$(($1 + $2)) | |
echo $result | |
return $result | |
} | |
sum 1 4 | |
# 5 |
This file contains hidden or 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
#!/bin/bash | |
noisy_work() { | |
not_a_real_command | |
} 2> /dev/null | |
sum() { | |
noisy_work | |
echo $(( $1 + $2 )) | |
} |
This file contains hidden or 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
#!/bin/bash | |
sum() { | |
echo $(( $1 + $2 )) | |
} | |
sum 1 4 | |
# 5 |
This file contains hidden or 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
// Least Recently Used (LRU) Cache w/ Doubly-Linked List implemented in JavaScript | |
// By @hackerrdave | |
function LRUCache(capacity) { | |
this.capacity = capacity; | |
this.map = {}; //store mapping of key => linked-list node reference | |
this.nodeCount = 0; | |
this.cacheHead = new Node(null); | |
this.cacheTail = this.cacheHead; | |
} |
This file contains hidden or 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
// Priority Queue ADT w/ Max Heap implemented in JavaScript | |
// By @hackerrdave | |
function PriorityQueue() { | |
this.heap = [null]; | |
} | |
function PriorityQueueNode(value, priority) { | |
this.value = value; | |
this.priority = priority; |
This file contains hidden or 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
// Quick Sort Algorithm implemented in JavaScript | |
// By @hackerrdave | |
function quickSort(arr) { | |
if (arr.length < 2) { | |
return arr; | |
} | |
let pivot = arr[0]; //let pivot point be the first element | |
let lesser = []; //track elements < the pivot value |
This file contains hidden or 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
// Merge Sort Algorithm implemented in JavaScript | |
// By @hackerrdave | |
function mergeSort(arr) { | |
if (arr.length < 2) { | |
return arr; | |
} | |
let midpoint = Math.floor(arr.length / 2); | |
let leftHalf = arr.slice(0, midpoint); //slice an array of left-half items |
This file contains hidden or 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 Ember from 'ember'; | |
export default Ember.Service.extend({ | |
eventInterval: 10000, | |
schedulePollEvent(event, interval) { | |
var eventInterval = interval || this.get('eventInterval'); | |
return Ember.run.later(()=>{ | |
event.apply(this); | |
this.set('timer', this.schedulePollEvent(event)); |
This file contains hidden or 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
def pascal(c: Int, r: Int) = { | |
def factorial(n: Int): Int = | |
if (n == 0) 1 else n * factorial(n - 1) | |
factorial(r) / ( factorial(c) * factorial(r - c) ) | |
} |
This file contains hidden or 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
// app/routes/index.js | |
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
authManager: Ember.inject.service(), | |
currentUser: Ember.computed.alias('authManager.currentUser'), | |
}); |
NewerOlder