Skip to content

Instantly share code, notes, and snippets.

View behnamazimi's full-sized avatar

Behnam behnamazimi

View GitHub Profile
<div class="square"></div>
<style>
.square {
width: 300px;
max-width: 100%;
}
.square::after {
content: '';
<div class="box">Simple Box</div>
<style>
.box {
color: #fff;
height: 250px;
margin: 2rem;
position: relative;
padding: 1rem;
@behnamazimi
behnamazimi / plink-plonk.js
Created February 17, 2020 08:42 — forked from tomhicks/plink-plonk.js
Listen to your web pages
@behnamazimi
behnamazimi / index.html
Last active January 15, 2020 07:51
Magical Subscribe Button
<div id="app"></div>
let user = { username: "bhnmzm", first_name: 'Behnam', last_name: "Azimi", title: "Front-End Developer" };
user[Symbol.iterator] = function*() {
for (let key in this) {
yield [key, this[key]];
}
};
for (let [key, value] of user) {
console.log(key + ": ", value)
const data = {
items: ["A", "B", "C"],
[Symbol.iterator]: function* myIterator() {
this.pointerIndex = 0;
while (this.pointerIndex < this.items.length)
yield this.items[this.pointerIndex++];
}
}
for (let item of data) {
function * myGenerator() {
// ... maybe some codes here
yield 'First Pause';
// ... maybe some codes here
yield 'Second Pause';
}
const it = myGenerator();
console.log(it.next()); //o: {value: "First Pause", done: false}
console.log(it.next()); //o: {value: "Second Pause", done: false}
console.log(it.next()); //o: {value: undefined, done: true}
const data = {
items: ["A", "B", "C"],
pointerIndex: 0,
next() {
if (this.pointerIndex < this.items.length) // if done
return { value: this.items[this.pointerIndex++], done: false }
else // if not done
return { value: undefined, done: true };
},
[Symbol.iterator]: function() {
const data = ["A", "B", "C"];
console.log(typeof data[Symbol.iterator]) //o: "function"
const iterator = data[Symbol.iterator]();
console.log(iterator.next()) //o: {value: "A", done: false}
console.log(iterator.next()) //o: {value: "B", done: false}
console.log(iterator.next()) //o: {value: "C", done: false}
console.log(iterator.next()) //o: {value: undefined, done: true}
const data = {
items: ["A", "B", "C"],
pointerIndex: 0,
[Symbol.iterator]: function () {
if (this.pointerIndex < this.items.length) // if done
return { value: this.items[this.pointerIndex++], done: false }
else // if not done
return { value: undefined, done: true };
}
}