Skip to content

Instantly share code, notes, and snippets.

View a-eid's full-sized avatar
🎯
Focusing

Ahmed Eid a-eid

🎯
Focusing
View GitHub Profile
@a-eid
a-eid / wtf.js
Created July 21, 2017 16:08 — forked from MichalZalecki/wtf.js
/* VT100 terminal reset (<ESC>c) */
console.log('\033c');
/* numbers comparations */
> '2' == 2
true
> '2' === 2
@a-eid
a-eid / urlencode.js
Created July 12, 2017 05:36
php like urlencode for javascript
// rawurlencode is more or less like encodeURIComponent
function urlencode (str) {
// php like urlencode for javascript
str = (str + '')
return encodeURIComponent(str)
.replace(/!/g, '%21')
.replace(/'/g, '%27')
.replace(/\(/g, '%28')
.replace(/\)/g, '%29')
.replace(/\*/g, '%2A')
/* takes single number and convert it to a position
@arg:
Int: number
@returns:
String: position (ie: 1st , 2nd , 3rd , 4th ,... 101st , 1004th ...)
*/
var calcPosition = (rank) => {
let final
let length = rank.toString().length
--length
""" Tower of Hanoi """
def printMove(fr , to):
print("move from {} to {} ".format(str(fr),str(to)) )
def towers(num , original , dist ,spare):
if num == 1:
printMove(original , dist)
else:
towers(num-1, original , spare , dist) # move the upper stack to spare to
towers(1, original , dist , spare) # move the bigger to to
const $ = document.querySelector.bind(document);
const $$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function (name, fn) {
this.addEventListener(name, fn);
};
NodeList.prototype.__proto__ = Array.prototype; // eslint-disable-line
NodeList.prototype.on = NodeList.prototype.addEventListener = function (name, fn) {
@a-eid
a-eid / issue.md
Last active June 26, 2017 18:18
medium issue extended

medium

Maybe I was not clear enough so I will explain the issue again after posting the versions you asked about

<html><!-- #BeginTemplate "/Templates/master.dwt" --><!-- DW6 -->
<head>
<!-- #BeginEditable "doctitle" -->
<title>Real Estate Puerto Rico ,Bienes Raices en Puerto Rico Clasificados Alquiler
Online</title>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="description" CONTENT="Real Estate Puerto Rico ,Bienes Raices en Puerto Rico Clasificados Alquiler Online">
<META NAME="keywords" CONTENT="Real Estate Puerto Rico , Alquiler Bienes Raices en Puerto Rico Clasificados Online, bienes raices puerto rico, puerto rico bienes raices, puerto rico real estate,real, estate, alquiler, rent, real estate, bienes raices, casa, clasificados, classifieds, puerto rico, online, homes, apartamento, house">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
import sys
from urllib.request import urlopen
def fetch_words(url):
words = []
with urlopen(url) as f:
for line in f:
for word in line.decode('utf-8').split():
words.append(word)
return words
function bubble_sort(arr){
for(let i = 0 , n = arr.length ; i < n - 1 ; n -= 1){
for(let ii = i , j = i + 1 ; j < n ; j += 1 , ii += 1){
if(arr[ii] > arr[j]){
let temp = arr[ii]
arr[ii] = arr[j]
arr[j] = temp
}
}
}

##what are generators##

  • They're pausable functions, pausable iterable functions, to be more precise
  • They're defined with the *
  • every time you yield a value, the function pauses until .next(modifiedYieldValue) is called
var myGen = function*() {
  var one = yield 1;
  var two = yield 2;
  var three = yield 3;
 console.log(one, two, three);