Skip to content

Instantly share code, notes, and snippets.

View iampava's full-sized avatar
💭
I code and teach JavaScript.

Alexandru Pavaloi iampava

💭
I code and teach JavaScript.
View GitHub Profile
@iampava
iampava / index.php
Created March 28, 2018 13:26
Dummy login form with PHP
<!DOCTYPE html>
<html lang="en">
<head></head>
<body>
<form class="form" id="loginForm" action="./login.php" method="POST">
<div class="form-group">
<label for="usernameInput"> Username </label>
<input type="text" id="usernameInput" name="username" required/>
@iampava
iampava / login.php
Last active March 28, 2018 13:21
Dummy login script in PHP
<?php
$realUser = "user";
$realPass = "1234";
if( isset($_POST["username"]) && isset($_POST["pass"])) {
// Do I have the username and passwords set?
// If yes, check their validity.
if( $_POST["username"] === $realUser && $_POST["pass"] === $realPass ) {
// Credentials are correct so let's redirect our user to the home page
@iampava
iampava / header.component.php
Created March 28, 2018 12:50
Reusable HTML "components" with PHP
<?php
function createHeader() {
return '
<header>
<h1>
<span class="emoji">🚀</span>
TW Checklist
<span class="emoji">🚀</span>
</h1>
</header>
@iampava
iampava / noInternetProject-playerMove.js
Last active January 24, 2018 08:58
Handling player-move actions by using a queue 🚀
let actionsQueue = [];
document.addEventListener('keydown', function (e) {
if(37 <= e.keyCode && e.keyCode <= 40) {
//Store only arrow keys
actionsQueue.push(e.keyCode);
}
});
// ...
@iampava
iampava / noInternetProject-paintOutline.js
Last active January 24, 2018 09:12
An overview of the logic inside the "paint" function.
let enemyList = [];
paint();
function paint() {
//This function gets called every frame
if(checkGameOver()) {
alert('Game over');
}
@iampava
iampava / noInternetProject-requestAnimationFrame.js
Created January 24, 2018 08:29
Small snippet showing how to use the "requestAnimationFrame" function to do some work every frame.
paint();
function paint() {
//This function gets called every frame
window.requestAnimationFrame(paint);
}
@iampava
iampava / hack-solution.js
Last active August 2, 2017 16:45
Hacking Javascript |
function PiggyBank(){
let money = [];
return {
store: function(index, value){
money[index] = value;
},
push: function(value){
money[money.length] = value; // with no function call, no vulnerability
}
}
@iampava
iampava / freaking-awesome-hack.js
Last active August 2, 2017 16:39
Hacking Javascript |
var money;
sharedPiggyBank.store('push', function(value) {
// YES, we can add properties to arrays!
this[this.length] = value;
money = this;
});
sharedPiggyBank.push('$22'); // resolves to the push method we added and not to Array.prototype.push
@iampava
iampava / hack.js
Last active August 2, 2017 16:38
Hacking Javascript |
var money;
Array.prototype.push = function(value){
this[this.length] = value; //we keep the intended push functionality so that mum doesn't notice we hacked the PiggyBank
money = this;
}
sharedPiggyBank.push('$22');
sharedPiggyBank.push('$33'); // money = ['$22', '$33'];
@iampava
iampava / piggy-bank.js
Last active June 8, 2021 02:34
Hacking Javascript |
function PiggyBank(){
let money = [];
return {
store: function(index, value){
money[index] = value;
},
push: function(value){
money.push(value);
}
}