Skip to content

Instantly share code, notes, and snippets.

View pmutua's full-sized avatar
🐲
Focus mode

Philip Mutua pmutua

🐲
Focus mode
View GitHub Profile
@pmutua
pmutua / remove_vowels.js
Created February 21, 2017 13:16
Simple function to remove vowels in a sentence
function removeVowels(sentence) {
var vowels = ['a', 'e', 'i', 'o', 'u'];
var newSentence = [];
for (var i = 0; i < sentence.length; i++) {
if (vowels.includes(sentence[i])) {
newSentence.push('-');
} else {
newSentence.push(sentence[i]);
}
}
@pmutua
pmutua / toRoman.js
Created February 22, 2017 09:37
simple code to convert numbers to roman numerals
function toRoman(num) {
var decimal = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
var roman = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];
var result = '';
for (var i = 0; i <= decimal.length; i++) {//look up the array decimal for values
//looping over every element of arrays
while (num % decimal[i] < num) {
//keep trying the same number until we need to move to a smaller one
result =result+ roman[i];
@pmutua
pmutua / simple-call-to-action.html
Created February 23, 2017 05:24
simple-call-to-action
<!--CAll to action-->
<div class="container text-center " id="background-call-action">
<h3 style="color: white">Get our daily food items delivered to your email</h3>
<form action="" class="form-inline">
<div class="form-group">
<input type="text" class="form-control" id="subscription" placeholder="Your email"></input>
<button type="submit" class="btn btn-default">Subscribe</button>
</div>
</form>
</div>
@pmutua
pmutua / form.html
Created February 24, 2017 13:16
pingpong
<div class="col-md-10">
<div class="content">
<!-- add a form-->
<form id="pingPongForm">
<h1>Let's play!</h1>
<h2>Rules!</h2>
<p>PingPong will count your number with the following exceptions</p>
<ol>
<li>Numbers divisible by 3 becomes "ping"</li>
<li>Numbers divisible by 5 becomes "pong"</li>
@pmutua
pmutua / pingpong.js
Created February 24, 2017 13:17
jspingpong
//user
$(document).ready(function() {
$("form#pingPongForm").submit(function(event) {
$("#userOutput").empty();
var userInput = parseInt($("input#number").val());
var result = pingPongFun(userInput);
result.forEach(function(output) {
$("#userOutput").append("<li>" + output + "</li>");
event.preventDefault();
});
'use strict'
const express = require('express')
const bodyParser =require('request')
const app =express()
app.set('port',(process.env.PORT || 5000))
// Allows us to process the data
app.use(bodyParser.urlencoded({extend:false}))
def calculate_tax(people):
while True:
try:
iterating_people = people.keys()
for key in iterating_people:
earning = people[key]
if earning <= 1000:
people[key] = 0
elif earning in range(1001,10001):
tax1 = 0 * 1000
@pmutua
pmutua / BankAccount.py
Last active April 25, 2017 12:45
BankAccount
class BankAccount:
def withdraw(self):
return
def deposit(self):
return
class SavingsAccount(BankAccount):
@pmutua
pmutua / manipulate_data.py
Created April 25, 2017 13:11
Data Structures Lab
def manipulate_data(data):
if isinstance(data, list):
return [sum(1 for n in data if isinstance(n, int) and n >= 0),
sum(n for n in data if isinstance(n, int) and n < 0)]
else:
return 'Only lists allowed'
@pmutua
pmutua / binary_converter.py
Created April 25, 2017 13:33
Algorithm to convert decimal numbers between 0 and 255 to their binary equivalents.
def binary_converter(dec):
if dec < 0 or dec > 255:
return "Invalid input";
return "{0:b}".format(dec)