Skip to content

Instantly share code, notes, and snippets.

View cefaijustin's full-sized avatar

Justin Cefai cefaijustin

View GitHub Profile
<div class="about-container" id="about-one">
<div class="nav-container">
<a class="nav-link"><%= image_tag "jclogo.png", class: "jclogo"%></a>
<nav>
<ul>
<li><a href="#web-apps">Web Apps</a></li>
<li><a href="#blog">Blog</a></li>
<li><a href="#tools">Tools</a></li>
const mergeSort = (arr) => {
if (arr.length < 2) return arr;
const middle = Math.floor(arr.length / 2);
const left = arr.slice(0, middle);
const right = arr.slice(middle);
return merge(mergeSort(left), mergeSort(right));
}
mergeSort = (arr) => {
if (arr.length < 2) return arr;
var middle = Math.floor(arr.length / 2);
var left = arr.slice(0, middle);
var right = arr.slice(middle, arr.length);
return merge(mergeSort(left), mergeSort(right));
}
merge = (left, right) => {
var result = [];
while (left.length && right.length) {
@cefaijustin
cefaijustin / blur.rb
Created October 24, 2018 22:48
Image Blur in Ruby
class Image
def initialize(array)
@array = array
@row_length = array.length
@col_length = array[0].length
end
def output_image
$(document).ready(function(){ // <-- IS THIS NECESSARY IF JS HAS OWN FILE?
// The taskHtml method takes in a Jacascript representation
// of the task and produces an HTML representation using
// <li> tags
function taskHtml(task) {
var checkedStatus = task.done ? "checked" : "";
var liClass = task.done ? "completed" : "";
@cefaijustin
cefaijustin / textPlusNumberArray.js
Created September 16, 2018 23:48
Find the sum of all elements in an array consisting of strings and numbers.
function addElements(arr) {
// create an array of the alphabet to find the numerical value of each letter in the input array
let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i",
"j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u",
"v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
"T", "U", "V", "W", "X", "Y", "Z"];
function findDupsMiss(arr) {
let missingNum = [];
let newArr = [];
arr = arr.sort((a, b) => a - b);
let dup = [...new Set(arr)];
for (let y = 1; y < dup.length; y++) {
if (dup[y] - dup[y - 1] != 1) missingNum.push(dup[y] - 1)
}
for (let i = 0; i < arr.length; i++) {
var alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXWZ";
var cipher = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXWZABCDEFGHIJKLM";
function rot13(message){
return message.split('').map(function(c) {
var i = alphabet.indexOf(c);
if (i < 0) {
// not in alphabet, return char
return c;
}
@cefaijustin
cefaijustin / rot13.js
Created August 19, 2018 01:55
Caesar Cipher Algorithm
function rot13(name) {
if (name.length === 0) return "Submission cannot be empty.";
let alphabet = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"];
let res = [];
name = name.toLowerCase().split("");
for (let i = 0; i < name.length; i++) {
for (let j = 0; j < alphabet.length; j++) {
if (name[i] === alphabet[j]) {
if (alphabet[j + 13] === undefined) {
res.push(alphabet[j - 13]);
@cefaijustin
cefaijustin / word_counter.rb
Created July 25, 2018 01:00
Ruby Hash Table Exercise
module WordCounter
def self.count(string)
return nil if !string || string == ""
string = string.downcase.gsub(/[\n.,?()]/, '').split(" ")
string.each_with_object(Hash.new(0)) { |word, counts| counts[word] += 1}
end
end