Skip to content

Instantly share code, notes, and snippets.

View vicsstar's full-sized avatar

Victor Igbokwe vicsstar

View GitHub Profile
@vicsstar
vicsstar / DLLPlayground.scala
Created March 4, 2021 04:36
An immutable dynamic linked list implementation, in scala.
object DLLPlayground {
trait DLList[+T] {
def value: T
def prev: DLList[T]
def next: DLList[T]
def isEmpty: Boolean
def prepend[S >: T](element: S): DLList[S]
@vicsstar
vicsstar / sr-migrate.sh
Last active May 28, 2020 12:33
Tiny script to quickly turn/ your Scrimba (scrimba.com) React project downloaded as a zip file, into a new "create-react-app" project.
#### Disclaimer ####
#### THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#!/bin/bash
####
#### Tiny script to quickly turn/ your Scrimba (scrimba.com) React project downloaded as a zip file, into a new "create-react-app" project.
#### This script is at least specific to the "React Bootcamp - Become a professional
@vicsstar
vicsstar / router.js
Last active September 4, 2019 21:00
Super Rentals
import EmberRouter from '@ember/routing/router';
import config from './config/environment';
const Router = EmberRouter.extend({
location: 'none',
rootURL: config.rootURL
});
Router.map(function() {
this.route('list-rentals');
@vicsstar
vicsstar / flames.js
Last active May 21, 2022 13:40
FLAMES game, written in JavaScript - I liked the logic behind the game and wanted to represent it in code
// flames.js
// FLAMES game. Algorithm can be found here: http://flamesgame.appspot.com/algorithm
const getFlame = (name1, name2) =>
name1.toLowerCase().split(''). // take all characters in "name1", to compare
filter(c => name2.toLowerCase().includes(c)). // keep only characters (in "name1") also found in "name2"
reduce((result, c) => [
result[0].replace(new RegExp(`${c}`, 'g'), ''), // replace common characters in "name1"
result[1].replace(new RegExp(`${c}`, 'g'), '') // replace common characters in "name2"
], [name1.toLowerCase(), name2.toLowerCase()]).
@vicsstar
vicsstar / QuickSortNoSideEffect.scala
Last active January 4, 2019 14:04
Simple QuickSort functions without side-effects in JavaScript and Scala #just-for-fun The tricks to make it "stateless", makes it slower - the algorithm becomes useless, almost, in the context of "quick sort" for large to really large lists. Little optimisation (with filtering & zipping). Then again, it's just for fun....
object QuickSort {
def sort(list: Seq[Int]): Seq[Int] = {
if (list.length < 2) list
else {
val midIndex = list.length / 2
val mid = list(midIndex)
val result = list.zipWithIndex.filter(_._2 != midIndex)
.partition(n => n._1 < mid)
result match {
@vicsstar
vicsstar / simple-tree.js
Created December 4, 2018 23:51
Implementation of a simple Tree data structure - tested with the common DOM structure
function createNode(key) {
const children = [];
const attributes = {};
return {
key,
children,
attributes,
addChild(key) {
const child = createNode(key);
@vicsstar
vicsstar / ReverseSentence.scala
Created June 23, 2018 23:15
Reverses a phrases/sentences without reversing the characters in the words.
object ReverseSentence extends App {
if (args == null || args.length == 0) {
printf("%d arguments found; 2 arguments required.", Option(args).map(_.length).getOrElse(0))
sys.exit(0);
}
if (args(0) == args(1)) {
println("The string parameters are equal.")
sys.exit(0)
}
@vicsstar
vicsstar / add_underscore_rule.js
Last active June 23, 2018 23:26
Tiny script that suffixes an underscore and number to a list of numbers, based on their index in their own group of equal numbers.
/*
* Replace the contents of the "string" variable with the actual input numbers you have.
* Make sure you space them, with each number on its own line.
*/
const numbers = `
2
1
2
3
1
@vicsstar
vicsstar / ListyMain.scala
Last active December 5, 2018 00:10
Basic scala list-like implementation.
object Main {
type T = Any
trait Listy[T] {
val value: T
def isEmpty: Boolean
def head: Option[T]
def tail: Listy[T]
def filter(predicate: T => Boolean): Listy[T] = {
if (predicate(value)) ListyImpl(value, tail.filter(predicate)) else tail
}
@vicsstar
vicsstar / Depreciation.java
Created February 8, 2018 00:56
Calculates depreciation value based on a cost and depreciation year.
import java.util.Scanner;
public class Depreciation {
private static Scanner scanner = new Scanner(System.in);
private static Column[] columns = {
new Column("Year", " "),
new Column("Start Value", " "),
new Column("Amt. Depreciated", " "),
new Column("Total Depreciation", "")
};