Skip to content

Instantly share code, notes, and snippets.

View greemwahr's full-sized avatar
🎯
Focusing

Greemwahr greemwahr

🎯
Focusing
  • Anonymous
View GitHub Profile
@greemwahr
greemwahr / readlineCalc.js
Created March 3, 2017 01:09
RisingStack Node Hero Readline Challenge
'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 February 18, 2017 18:45
Vue component for desktop notification
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,
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)
})
})
# 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!
<html>
<head>
<title>Information Gathered</title>
</head>
<body>
<!--
You embed PHP code between tags
function factorialize(num) {
factorialArr = [];
if (num === 0) {
factorialArr = [1];
} else {
for (i = 1; i < num + 1; i++) {
factorialArr.push(i);
}
}
@greemwahr
greemwahr / isIsogram.js
Created November 2, 2015 01:03
codeSnippet
function isIsogram(str){
//.....
if (str === null) {
return false;
} else {
var strInput = str.toLowerCase();
var repeatedChr = (/([a-zA-Z]).*?\1/).test(strInput);
return !repeatedChr;
}
}
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];
}
@greemwahr
greemwahr / isPrime.js
Created November 1, 2015 02:21
codeSnippet
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;
}
/* 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);