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
/** | |
* Create a function which will call the callback function | |
* after the given amount of milliseconds has passed since | |
* the last time the callback function was called. | |
*/ | |
const idle = (callback, delay) => { | |
let handle; | |
return () => { | |
if (handle) { |
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 React, { Component } from 'react'; | |
import { findDOMNode } from 'react-dom'; | |
/** | |
* A higher order component which scrolls the user to the bottom of the | |
* wrapped component, provided that the user already was at the bottom | |
* of the wrapped component. Useful for chats and similar use cases. | |
* @param {number} treshold The required distance from the bottom required. | |
*/ | |
const scrollToBottom = (treshold = 0) => WrappedComponent => { |
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 minegenkode; | |
import java.util.ArrayList; | |
import java.util.List; | |
import java.util.concurrent.ThreadLocalRandom; | |
public class LightsOut { | |
private List<Integer> board; | |
public LightsOut() { |
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
from math import exp | |
def f(x): | |
y = (x-12)*exp(5*x) - 8*(x+2)**2 | |
return y | |
def g(x): | |
y = - x - 2*x**2 - 5*x**3 + 6*x**4 | |
return y |
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
<script type="text/javascript"> | |
(function() { | |
var MathJax = document.createElement("script"); | |
MathJax.async = true; | |
MathJax.src = "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_CHTML"; | |
var s = document.getElementsByTagName("script")[0]; | |
s.parentNode.insertBefore(MathJax, s); | |
})(); | |
</script> |
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 getIndex = (permutation, affected) => { | |
const indexes = affected.map(i => permutation.indexOf(i)); | |
if (affected.length === 1) { | |
return permutation.indexOf(affected[0]); | |
} | |
let base = permutation.length; | |
let index = indexes[indexes.length - 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
const cantor = (arr) => { | |
if (arr.length === 2) { | |
return 1 / 2 * (arr[0] + arr[1]) * (arr[0] + arr[1] + 1) + arr[1]; | |
} | |
return cantor( | |
arr.slice(0, arr.length - 2) | |
.concat( | |
cantor([arr[arr.length - 1], arr[arr.length - 2]]) | |
) |
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
def is_leap_year(year): | |
if year % 400 == 0: | |
return True | |
elif year % 100 == 0: | |
return False | |
elif year % 4 == 0: | |
return True | |
return False | |
days = ('man', 'tir', 'ons', 'tor', 'fre', 'lor', 'son') |
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 NumberTheory = {}; | |
/** | |
* @param {number} n | |
* @param {number} k | |
*/ | |
NumberTheory.binomial = function(n, k) { | |
if (n === k) return 1; | |
if (k === 1) return n; | |
return binomial(n - 1, k) + binomial(n - 1, k - 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
// Prototype that stores information about a given polynomial. | |
function Polynomial(data) { | |
// Support providing already existing Polynomials. | |
this.polynomial = data instanceof Polynomial ? data.polynomial : data; | |
} | |
// Rank all coefficients in the polynomial and return the largest. | |
Polynomial.prototype.getLargestCoefficient = function() { | |
var re = /(\d+)/g, match, max = 0; | |
while(match = re.exec(this.getPolynomial())) |