Skip to content

Instantly share code, notes, and snippets.

View CodeSigils's full-sized avatar

CS CodeSigils

  • Freelancer
  • Athens, Greece
View GitHub Profile
function shouter(whatToShout) {
return whatToShout.toUpperCase() + '!!!';
}
// tests
function testShouter() {
var whatToShout = 'fee figh foe fum';
var expected = 'FEE FIGH FOE FUM!!!';
if (shouter(whatToShout) === expected) {
@CodeSigils
CodeSigils / gist:0dcd0aec7a48a2716e5f8ace3d4d1274
Last active October 25, 2016 18:26
Wise person generator
function wisePerson(wiseType, whatToSay) {
return 'A wise ' + wiseType + ' once said: "' + whatToSay + '".';
}
wisePerson('goat', 'hello world');
// tests
function testWisePerson() {
var wiseType = 'goat';
var whatToSay = 'hello world';
function textNormalizer(text) {
return text.toLowerCase().trim();
}
// tests
function testTextNormalizer() {
var text = " let's GO SURFING NOW everyone is learning how ";
var expected = "let's go surfing now everyone is learning how";
if (textNormalizer(text) === expected) {
function typoCorrector(sourceText, target, value) {
// var matchPattern = target.match(/[A-Za-z]/g);
var matchPattern = new RegExp(target, 'g');
var matchCount = (sourceText.match(matchPattern) || []).length;
console.log(
"Replacing " + matchCount + " instances of " + target + " with " + value);
return sourceText.replace(matchPattern, value);
}
// =================== Square Area =================== //
// Create a function called computeArea that takes two arguments: width and height.
// It returns the area of a square whose width is width and height is height.
// So computeArea(2, 2) would return 4, and computeArea(3, 5) would return 15.
function computeArea(width, height) {
return width * height;
}
// tests
/* ======= Traffic Lights =======
* You need to modify and update the
* JSBin below, so that when users
* click on the button, a randomly
* chosen traffic light turns on.
*/
function doTrafficLights() {
var activeLight = getActiveLight();
@CodeSigils
CodeSigils / gist:32873be8f9a5141f46b37f562aee8b74
Last active October 22, 2016 08:59
Challenge: In your own words
Q: Why are global variables avoided?
A: Because their values can be overwritten by the values of local variables.
Local scope (function scope) can have access to global scope.
Sometimes this can be useful like when we want global access to a library
like JQuery in all our files. Or we want a function to have access in a database.
Q: Explain JavaScript's strict mode
A: When 'strict mode' is enabled declaring a variable without the var keyword, will rise an error.
The 'use strict' command can be put at the top of a file to enforce strict mode for the entire file.
@CodeSigils
CodeSigils / max-min-drill.js
Last active April 3, 2018 08:29
Arrays and Loops Drills
/* ======= max and min (without sort) ======= */
/*
To complete this drill, you need to implement two functions, max and min.
Both functions should take a single argument: a list of numbers called numbers.
max(myNumbers) should return the largest number in the list, while min(myNumbers)
should return the smallest.
Assume that the numbers input only contains numbers (that is, you don't have to
inspect your inputs to confirm they only contain numbers).
// ========= Most frequent word ========= //
/* In this drill, you need to implement a function named mostFrequentWord.
This function takes a single argument, words. Words is an array of lowercase strings,
with punctuation stripped out.
*/
function mostFrequentWord(words) {
// `words` is an array of strings.
// Create an empty object to hold most frequent words.
var wordsObj = {};
@CodeSigils
CodeSigils / duplicity_pass_B2.sh
Last active November 20, 2018 13:08
A simple script using Duplicity and pass for Backblaze cloud encrypted backups
#!/bin/sh
# A simple script using Duplicity and pass
# for cloud encrypted Backblaze backups
# Basic Duplicity syntax examples:
# https://www.systutorials.com/docs/linux/man/1-duplicity/
#
# 1. duplicity [source language="directory"][/source] file://[destination directory]
#