Skip to content

Instantly share code, notes, and snippets.

View joker314's full-sized avatar

Max joker314

  • United Kingdom
View GitHub Profile
@joker314
joker314 / object-reverser.js
Created November 1, 2018 13:48
A function to reverse an object. For example, {a: "b", c: "d"} would become {b: "a", d: "c"}
/**
* A function to swap keys with values
* in a JavaScript object.
*
* {a: 'b', c: 'd'} => {b: 'a', d: 'c'}
*/
function reverseObject(obj) {
const reducer = (accumulator, [key, value]) => Object.assign(accumulator, {[value]: key})
return Object.entries(obj).reduce(reducer, {})
@joker314
joker314 / gist:2f5c26d8b9d213a57fabdc9bbdd384d2
Last active March 18, 2018 23:07 — forked from QuincyLarson/gist:c21fde97e43a27618694f12f3ee9e25a
freeCodeCamp production challenge URLs
/challenges/learn-how-freecodecamp-works
/challenges/challenges/basic-html-and-html5/learn-how-freecodecamp-works
/challenges/join-a-freecodecamp-study-group-in-your-city
/challenges/basic-html-and-html5/join-a-freecodecamp-study-group-in-your-city
/challenges/iterate-odd-numbers-with-a-for-loop
/challenges/basic-javascript/iterate-odd-numbers-with-a-for-loop
/challenges/count-backwards-with-a-for-loop
@joker314
joker314 / xss.md
Last active December 31, 2017 18:33

What is XSS

XSS stands for Cross-site scripting, and it's a security vulnerability. It's when an attacker can inject certain code into a vulnerable website, which could decieve or take over an account of a victim.

How does it work?

Let's say I have an input field on my website, where anybody can leave a comment. This comment will, for simplicity, replace the previous comment.

<div>
Hah! This is such a cool site!

Ok, so, you might know about JavaScript regular expressions. Well, here is a tutorial about them, but written by a 13 year old, so it isn't actually any good!

Regular expressions go between / characters. Here is an exampe, /hi/.

Ok, now then. Let's learn how to match the string abc. Well, that's quite simple.

/abc/. Yey! So putting letters next to each other makes them match one after the other.

Ok, now, after the second / we can put a g to make it match globally, that is, we can extract abc from xyzabcghi.

// Solution below
@joker314
joker314 / price.txt
Created March 9, 2017 22:40
So how many pounds?
£(log(2*2^2+2)*7/2+18/4)/(2^(4^3-(3^3+5*7-1)))-1
""" This is a grammar file for the ATC #3 challenge by @MegaApuTurkUltra """
if => "IF" condition result result
condition => result "EQUALS" result
| result "LESSTHAN" result
| result "GREATERTHAN" result
protect => "PROTECT" reference