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
package com.springmvc.model; | |
import org.springframework.util.concurrent.ListenableFuture; | |
import java.util.concurrent.CompletableFuture; | |
/** | |
* Converts a listenable future to a completable future, mapping the listenable futures' callbacks | |
* to the completable futures' equivalents. | |
*/ |
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
// converted from C code from p.6 of the btc whitepaper | |
// tested with p.7's provided sample inputs | |
// q being the probability the attacker finds the next block | |
// z being the number of blocks the attacker is behind | |
var AttackerSuccessProbability = function(q, z) { | |
var p = 1.0 - q; | |
var lambda = z * (q / p); | |
var sum = 1.0; | |
var poisson; |
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
var binarySearch = function (a, x) { | |
var low = 0, | |
high = a.length - 1, | |
mid; | |
while (low <= high) { | |
mid = Math.floor((low + high) / 2); | |
if (a[mid] < x) | |
low = mid + 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
var hasComplement = function (array, sum) { | |
if (sum < 0) | |
throw "sum must be bigger than 0"; | |
var complements = []; | |
for (var i = 0, complement; i < array.length; i++, complement = sum - array[i]) { | |
if (array.indexOf(complement) != -1) // if (complement.indexOf(array[i]) != -1) | |
return true; | |
else |
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
const COMMAND = { | |
next: '>', | |
prev: '<', | |
increment: '+', | |
decrement: '-', | |
print: '.', | |
accept: ',', | |
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
function Node (name) { | |
this.name = name; | |
this.left = null; | |
this.right = null; | |
} | |
function BinaryTree (node) { | |
this.node = node; | |
this.visit = function(fn) { |
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
function Node (name) { | |
this.name = name; | |
this.children = []; | |
} | |
function Tree (node) { | |
this.node = node; | |
this.visit = function(fn) { | |
return fn(this.node); |
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
let selectionSort = (t) => { | |
for (let i = 0; i < t.length; i++) { | |
let min = i; | |
for (let j = i + 1; j < t.length; j++) { | |
if(t[j] < t[min]) | |
min = j; | |
} | |
[t[min], t[i]] = [t[i], t[min]]; | |
} |
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
let shuffle = function (playlist) { | |
let shuffledPlaylist = [], | |
song; | |
while (playlist.length !== 0) { | |
song = Math.floor(Math.random() * playlist.length); | |
shuffledPlaylist.push(playlist[song]); | |
playlist.splice(song, 1); | |
} | |
return shuffledPlaylist; |
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
// Fizz if i % 3 == 0, Buzz if i % 5 == 0, FizzBuzz if both | |
for(i=1;i++<=100;)i%3==0||i%5==0?console.log(i%3==0?'Fizz':''+i%5==0?'Buzz':''):0 // 82 | |
for(i=1;i++<=100;)[i%3,i%5].some(x=>x==0)?console.log(i%3==0?'Fizz':''+i%5==0?'Buzz':''):0; // 91 | |
for(i=1;i++<=100;)i%3==0||i%5==0?console.log(i%3==0?'Fizz':''+i%5==0?'Buzz':$):$ // 80 | |
for(i=1;i++<=100;)[j,k]=[i%3==0,i%5==0],j||k?console.log(j?'Fizz':''+k?'Buzz':$):$ // 82 | |
for(i=1;i++<=100;[j,k]=[i%3==0,i%5==0])j||k?console.log(j?'Fizz':''+k?'Buzz':''):0 // 82 | |
for(i=1;i++<=100;[j,k]=[i%3==0,i%5==0])j||k?console.log(j?'Fizz':''+k?'Buzz':$):0 // 81 | |
for(i=1;i++<101;[j,k]=[i%3==0,i%5==0])j||k?console.log(j?'Fizz':''+k?'Buzz':$):0 // 80 | |
for(i=1;i++<101;)i%3==0||i%5==0?console.log(i%3==0?'Fizz':''+i%5==0?'Buzz':$):0 // 79 |
OlderNewer