Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Sherif O. greemwahr

🎯
Focusing
View GitHub Profile
@greemwahr
greemwahr / readlineCalc.js
Created Mar 3, 2017
RisingStack Node Hero Readline Challenge
View readlineCalc.js
'use strict'
// app/readlineCalc.js
const readline = require('readline')
// const calc = require('./calc')
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
})
@greemwahr
greemwahr / desktopNotificator.js
Created Feb 18, 2017
Vue component for desktop notification
View desktopNotificator.js
Vue.component('desktop-notificator', {
props: ['message', 'title'],
template: '<button v-on:click="notify()">??</button>',
methods: {
notify: function() {
if (Notification.permission !== "granted") {
Notification.requestPermission();
} else {
new Notification(this.title, {
body: this.message,
View nodeIODirFileFilter.js
var fs = require('fs')
var path = require('path')
fs.readdir(process.argv[2], function (err, list) {
list.forEach(function (file) {
if (path.extname(file) === '.' + process.argv[3])
console.log(file)
})
})
View nodeIOFileRead.js
# Process I/O files synchronously in node.js
var fs = require('fs')
var contents = fs.readFileSync(process.argv[2])
var lines = contents.toString().split('\n').length - 1
console.log(lines)
// note you can avoid the .toString() by passing 'utf8' as the
// second argument to readFileSync, then you'll get a String!
View learnphp.php
<html>
<head>
<title>Information Gathered</title>
</head>
<body>
<!--
You embed PHP code between tags
View factorialize.js
function factorialize(num) {
factorialArr = [];
if (num === 0) {
factorialArr = [1];
} else {
for (i = 1; i < num + 1; i++) {
factorialArr.push(i);
}
}
View isIsogram.js
function isIsogram(str){
//.....
if (str === null) {
return false;
} else {
var strInput = str.toLowerCase();
var repeatedChr = (/([a-zA-Z]).*?\1/).test(strInput);
return !repeatedChr;
}
}
View alphabetPosition.js
function alphabetPosition(text) {
var textWithoutSymbols = text.replace(/[^\w]|_|\d/g, "").toLowerCase();
var objAlphabet = {"a" : 1, "b" : 2, "c" : 3, "d" : 4, "e" : 5, "f" : 6, "g" : 7, "h" : 8, "i" : 9, "j" : 10, "k" : 11, "l" : 12, "m" : 13, "n" : 14, "o" : 15, "p" : 16, "q" : 17, "r" : 18, "s" : 19, "t" : 20, "u" : 21, "v" : 22, "w" : 23, "x" : 24, "y" : 25, "z" : 26}
var alphaNumericCypher = textWithoutSymbols.split("").map(function (a) {
for(var key in objAlphabet) {
if(objAlphabet.hasOwnProperty(key)) {
if (key === a) return objAlphabet[key];
}
View isPrime.js
function isPrime(num) {
var absNum = Math.abs(num);
if (absNum <= 1) {
return false;
} else if (absNum <= 3) {
return true;
} else if (absNum % 2 === 0 || absNum % 3 === 0) {
return false;
}
View indicesOfSearchedElement.js
/* Excellent piece of code to determine the index of a particular
element being searched.*/
var indices = [];
var element = 0;
var idx = arrNum.indexOf(element);
// console.log(idx);
while (idx != -1) {
indices.push(idx);
idx = arrNum.indexOf(element, idx + 1);