Skip to content

Instantly share code, notes, and snippets.

View scriptype's full-sized avatar
🍁

Mustafa Enes Ertarhanaci scriptype

🍁
View GitHub Profile
@scriptype
scriptype / index.html
Created February 26, 2017 21:05
MpYKVq
<div class="game">
<h1 class="game__title">Satisfy the inputs</h1>
<div class="game__screen" id="game-screen"></div>
<div class="game__hud">
<div class="game__lives" id="game-lives"></div>
<div class="game__score" id="game-score"></div>
</div>
</div>
@scriptype
scriptype / callback-heaven.js
Created February 3, 2017 20:16
Callback heaven
function create(callback) {
setTimeout(function() {
callback('created')
}, Math.random() * 1000)
}
function read(value, callback) {
setTimeout(function() {
callback(value + ', red')
}, Math.random() * 1000)
@scriptype
scriptype / index.html
Created January 30, 2017 11:17
dynamic property assignment new vs old way (http://jsbench.github.io/#5f64c399dca1faff56f705e7efd46e7f) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>dynamic property assignment new vs old way</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@scriptype
scriptype / index.js
Created December 31, 2016 22:47
Toplist-as-a-counter
window.onbeforeunload = e => {
postList(url, {
nick: "onbeforeunload yes",
message: "success ok " + Date.now()
}).then(() => {
console.log('posted √')
}).catch(e => {
console.log('couldnt post', e)
})
}
@scriptype
scriptype / index.js
Created December 31, 2016 18:05
Get data from Toplist-as-a-db
fetch('/list.htm')
.then(response => response.text())
.then(html => {
var dom = document.createElement('div')
dom.innerHTML = html
var content = dom.querySelector('#content')
var table = content.querySelector('table tbody')
var list = Array.from(table.querySelectorAll('tr')).slice(1)
var entries = list.map(entry => {
var cell = entry.querySelector('td:nth-child(2)')
@scriptype
scriptype / index.js
Last active December 31, 2016 18:05
Toplist-as-a-db
var form = new FormData()
var unique = crypto.getRandomValues(new Int32Array(3)).join('-')
form.set('modulenter[titel]', 'db-entry 5')
form.set('modulenter[url]', `http://${unique}.com`)
form.set('modulenter[name]', 'dba')
form.set('modulenter[email]', 'db@entry.ok')
form.set('email', 'ZmxhYQD3BQtfYwD4ZvjlYwLkYQZ4YwDfZGRkYvjmBQD2')
form.set('mode', 'addlink')
form.set('modulenter[text]', JSON.stringify({
nick: "scriptype",
@scriptype
scriptype / index.html
Created December 21, 2016 16:41
.map().join() vs .reduce() (http://jsbench.github.io/#0041b8df43a03dc10a2e82173b3dc6c1) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>.map().join() vs .reduce()</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@scriptype
scriptype / index.html
Created December 21, 2016 14:48
.map().join() vs .reduce() (http://jsbench.github.io/#a80c1e0e7282af6742adbbea4dfdf50a) #jsbench #jsperf
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>.map().join() vs .reduce()</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
@scriptype
scriptype / xor-pseudorandom-encryption.js
Last active November 18, 2016 18:26
Encryption with XOR and non-secure PRNG
function toBinary(plainText) {
return plainText.split('').map(c => {
return ('0'.repeat(BIT_COUNT) + c.charCodeAt(0).toString(2)).slice(-BIT_COUNT)
})
}
function generateKey(len) {
return ' '.repeat(len * BIT_COUNT).split('').reduce(p => p + ~~(Math.random() * 2), '')
}
@scriptype
scriptype / app.js
Last active October 26, 2016 11:41
Single Page Application that doesn't depend on a framework
function EventEmitter(options) {
this._listeners = {}
}
EventEmitter.prototype.on = function(event, handler) {
this._listeners[event] = this._listeners[event] || []
this._listeners[event].push(handler)
}
EventEmitter.prototype.off = function(event, handler) {