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 randomIntOf = i => ~~(i * Math.random()); | |
const randomOffsetFrom = i => (Math.random() * (i + 200) - 100); | |
function insertRandomFood() { | |
const taco = "\ud83c\udf2e"; | |
const burrito = "\ud83c\udf2e"; | |
const food = [taco, burrito]; | |
const randomFood = food[randomIntOf(2)]; | |
const int = randomIntOf(100); | |
const style = { |
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 cat = { | |
get state() { | |
delete this.state; | |
this.state = Math.random() >= 0.5 ? 'Alive' : 'Dead'; | |
return this.state; | |
} | |
}; |
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
public void pmn() | |
{ | |
try | |
{ | |
var methodName = (new System.Diagnostics.StackTrace()).GetFrame(1).GetMethod(); | |
System.Diagnostics.Debug.WriteLine(methodName); | |
} | |
catch (Exception ex) | |
{ | |
System.Diagnostics.Debug.WriteLine($"Failed to print method name: ${ex.Message}"); |
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 copyToClipboard(element) { | |
if (element.select) { | |
element.select(); | |
document.execCommand('copy'); | |
} else { | |
let range = document.createRange(); | |
range.selectNodeContents(outputText); | |
let selection = window.getSelection(); | |
selection.removeAllRanges(); | |
selection.addRange(range); |
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
#!/usr/bin/env ruby | |
require 'date' | |
today = Date.today | |
first_day = Date.new(today.year, today.month, 1) | |
last_day = Date.new(today.year, today.month, -1) # A trick from JavaScript, heh... | |
first_week_blank_count = first_day.wday | |
last_week_blank_count = last_day.wday |
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
// Impure | |
reduce = (f, i, l) => (n = [...l]).length ? r(f, f(i, n.pop()), n) : i | |
// Impure and minified | |
r=(f,i,l)=>(n=[...l]).length?r(f,f(i,n.pop()),n):i | |
// Pure | |
reduce = (reducerFunction, initialValue, enumerable) => | |
enumerable.length |
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 fizzbuzz-nums (range 1 101)) | |
(defn fizz? [n] (zero? (rem n 3))) | |
(defn buzz? [n] (zero? (rem n 5))) | |
(defn fizzbuzz? [n] (and (fizz? n) (buzz? n))) | |
(defn fizzbuzz [n] | |
(cond (fizzbuzz? n) "FizzBuzz" | |
(fizz? n) "Fizz" | |
(buzz? n) "Buzz" |
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
/** | |
* A simple function to catch when elements are added to a specified container element. | |
* @author Most of this code is from a StackOverflow post I can't find right now. I wrapped it into a reusable function. | |
* @param {HTMLElement} containerElement - The container element to watch for added nodes. | |
* @param {function} eventHandlerFunction - The function to call when a node is added to the containerElement. | |
*/ | |
function onDOMInsert(containerElement, eventHandlerFunction) { | |
if (typeof MutationObserver === 'function') { | |
var observer = new MutationObserver(function (m) { | |
for (var i = 0; i < m.length; i++) { |
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
(define (reduce f i l) | |
(if (null? l) | |
i | |
(f i (reduce f (car l) (cdr l))))) |
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 active = false; | |
function changeRefer(details) { | |
if (!active) return; | |
for (var i = 0; i < details.requestHeaders.length; ++i) { | |
if (details.requestHeaders[i].name === 'Referer') { | |
details.requestHeaders[i].value = 'http://www.google.com/'; | |
break; | |
} |