View append-guard.js
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
// Store a reference to the native appendChild function | |
const nativeAppend = Node.prototype.appendChild; | |
// Override the appendChild method | |
Node.prototype.appendChild = function(node) { | |
// If the node is a "robber" don't append it | |
if (node.id === 'robber') { | |
console.log('denying robber entry to the bank'); | |
return; | |
} |
View mutation-observer-guard.js
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
// Select the node that will be observed for mutations | |
const bank = document.getElementById('bank'); | |
// Options for the observer (which mutations to observe) | |
const config = { childList: true }; | |
// Callback function to execute when mutations are observed | |
const callback = function(mutationsList, observer) { | |
// Loop through all mutations | |
mutationsList.forEach(mutation => { |
View array-proto-override-preserve.js
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 items = ['apple', 'orange', 'banana']; | |
// Here we are storing a reference to the native Array push method | |
const nativePush = Array.prototype.push; | |
Array.prototype.push = function(item) { | |
console.log(`Array push intercepted. Pushing ${item} into [${this}]`); | |
// Push the item into the array | |
nativePush.call(this, item); | |
} |
View array-proto-override.js
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 items = ['apple', 'orange', 'banana']; | |
Array.prototype.push = function(item) { | |
console.log(`Array push intercepted. Pushing ${item} into [${this}]`); | |
} | |
items.push('grape'); // Will log the above statement to the console |
View Director.js
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
class Director { | |
constructor(builder) { | |
this.builder = builder; | |
} | |
constructFamilyHouse() { | |
return this.builder | |
.buildWalls(4) | |
.buildRoof('sloped') | |
.buildGarden(['trees', 'grass', 'peacocks']) |
View Builder.js
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
class House { | |
constructor() { | |
this.walls = null; | |
this.roof = null; | |
this.pool = null; | |
this.garden = null; | |
this.internet = null; | |
} | |
setWalls(walls) { |
View AbstractFactory.js
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
class DressClothesFactory { | |
constructor() { | |
} | |
getShoes() { | |
return new DressShoes(); | |
} | |
getShirt() { |
View signedurls.php
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
<?php | |
$adapter = Storage::getAdapter(); | |
$client = $adapter->getClient(); | |
$bucket = $adapter->getBucket(); | |
$cmd = $client->getCommand('PutObject', [ | |
'Bucket' => $bucket, | |
'Key' => 'ItWorks' | |
]); |