Skip to content

Instantly share code, notes, and snippets.

View jonathandannel's full-sized avatar

Jonathan Dannel jonathandannel

  • Toronto, ON, Canada
View GitHub Profile
@jonathandannel
jonathandannel / lol-nocomment.js
Last active December 30, 2019 18:43
lol-nocomment
const [mainPlayerData, setMainPlayerData] = useState(null);
const [otherPlayerData, setOtherPlayerData] = useState(null);
const getPlayerParticipantId = (accountId, data) =>
data.participantIdentities.find(({ player }) => player.accountId === accountId).participantId;
const getNameFromParticipantId = (data, id) =>
data.participantIdentities.find(({ participantId }) => participantId === id).player.summonerName;
const getRelevantStats = stats => {
@jonathandannel
jonathandannel / lol.js
Last active December 30, 2019 18:27
lol
const accountId = "USJ23mFRVd7vw4cZJpb2GD8t3QF1Qsa6TusCvCkQN4uD0_Q"
// Helper functions:
// Find the object that tells us the participant ID of the player whose account key we know
const getPlayerParticipantId = (accountId, data) => {
const { participantId } = data.participantIdentities.find(({ player }) => player.accountId === accountId)
return participantId;
}
const accountId = "USJ23mFRVd7vw4cZJpb2GD8t3QF1Qsa6TusCvCkQN4uD0_Q"
// Helper functions:
// Find the object that tells us the participant ID of the player whose account key we know
const getPlayerParticipantId = (accountId, data) => {
const { participantId } = data.participantIdentities.find(({ player }) => player.accountId === accountId)
return participantId;
}
@jonathandannel
jonathandannel / asd.js
Created February 13, 2019 20:31
google load
'page.googlesidebar.load': async (props = {}) => {
const { default: librarianReducer } = await import('./reducers/librarian');
const store$ = new BehaviorSubject();
combineLatest(
action$ |> scan(librarianReducer, undefined),
user$,
Object.assign.bind({}),
).subscribe(store$);
function sumItems(array) {
var total = 0;
array.forEach((item) => {
if (Array.isArray(item)) {
total += sumItems(item);
} else {
total += item;
}
})
return total;
@jonathandannel
jonathandannel / get.js
Created June 30, 2018 20:59
users/:id
app.get('/users/:id', (req, res) => {
let user = req.params.id;
knex('users')
.where({ id: user })
.then((row) => {
let info = {
name: '',
maps: [],
favorites: []
};
@jonathandannel
jonathandannel / diceroll.js
Last active June 5, 2018 15:35
W1D2 - Dice Roller
var input = Number(process.argv.slice(2));
function rollDice(numRolls) {
var result = [];
for (var i = 0; i < numRolls; i++) {
result.push(Math.floor(Math.random() * 6 + 1));
}
console.log(`Rolled ${numRolls} dice: ` + result.join(', '));
}
@jonathandannel
jonathandannel / passwordrefactor.js
Created June 5, 2018 00:29
W1D1 - Password Obfuscator Refactor
var input = process.argv[2];
var obfuscate = function(str) {
var result = str.split('');
var replaceLibrary = { 'a': '4', 'e': '3', 'o': '0', 'l': '1' };
for (i = 0; i < Object.keys(replaceLibrary).length; i++) {
for (j = 0; j < result.length; j++) {
if (Object.keys(replaceLibrary)[i] == result[j]) {
result[j] = Object.values(replaceLibrary)[i];
@jonathandannel
jonathandannel / piglatin.js
Created June 4, 2018 21:12
W1D1 Stretch - Pig Latin
var input = [];
for (i = 2; i <= process.argv.length - 1; i++) {
input.push(process.argv[i]);
};
var pigLatin = function(input) {
var result = '';
for (i = 0; i < input.length; i++) {
@jonathandannel
jonathandannel / reverse.js
Created June 4, 2018 19:10
W1D1 Stretch - Reverse
var input = [];
for (i = 2; i <= process.argv.length - 1; i++) {
input.push(process.argv[i]);
};
var reverse = function(arr) {
var stringArr = [];
var result = '';
for (i = 0; i < arr.length; i++) {