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 React = require('react'); | |
var ListItem = require('./ListItem.jsx'); | |
var ingredients = [{"id":1,"text":"ham"}, {"id":2,"text":"cheese"},{"id":3,"text":"Tomato"}]; | |
class List extends React.Component { | |
render() { | |
const listItems = ingredients.map((item) => (<ListItem key={item.id} ingredient={item.text} />)); | |
return ( | |
<ul>{listItems}</ul> |
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
[...document.querySelectorAll('*')] | |
.map((e) => ({ | |
element: e, | |
listeners: Object.keys(getEventListeners(e)) | |
.map((k) => ({ | |
event: k, | |
listeners: getEventListeners(e)[k] | |
})) | |
})) | |
.filter((item) => item.listeners.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
const parseSelection = () => { | |
const s = window.getSelection(); | |
const aText = s.anchorNode.textContent; | |
const eText = s.extentNode.textContent; | |
const aOffset = s.anchorOffset; | |
const eOffset = s.extentOffset; | |
const lineBreaks = '\n\n'; | |
const selectedText = s.toString(); | |
console.log( |
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
Object.keys(localStorage).filter(key => key.slice(0, 7) === 'lscache').forEach(key => localStorage.removeItem(key)) |
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
// Repl.it that logs out several of the operations so you can experiment and see how the function works | |
// Link: https://repl.it/@JH108/Bitwise-fun | |
// If curious as to how it works see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Bitwise_Operators | |
function hexToRgbA(hex){ | |
var c; | |
// Check to ensure that the string is a valid hex value | |
if(/^#([A-Fa-f0-9]{3}){1,2}$/.test(hex)){ | |
// Remove the # from the value and split into an array | |
c= hex.substring(1).split(''); |
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
# Customizes the text displayed in the terminal to look like ~/code/projects (master). Git branches are shown. | |
parse_git_branch() { | |
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
} | |
low_pri() { | |
command="$@" | |
echo $command | |
nice -n 5 $command | |
} | |
text() { |
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
https://jsperf.com/substring-attributes-and-different-looping-mechanisms/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 states = { | |
PENDING: "pending", | |
FULFILLED: "fulfilled", | |
REJECTED: "rejected" | |
}; | |
const isThenable = maybePromise => | |
maybePromise && typeof maybePromise.then === "function"; | |
class CustomPromise { |
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 setupTournament(number, games) { | |
const scores = []; | |
const leaderboard = []; | |
// Set all points against and for to 0 | |
for (var i = 0; i < number; i++) { | |
scores[i] = {} | |
scores[i].for = 0; | |
scores[i].against = 0; | |
scores[i].key = i; |
OlderNewer