Skip to content

Instantly share code, notes, and snippets.

@dev-sampsonorson
dev-sampsonorson / tinyfly.loading.js
Created September 23, 2011 17:02 — forked from tinyfly/tinyfly.loading.js
Add and remove loading animation to ajax calls (jQuery)
// This code depends on jQuery
//create 1 global variable for namespacing purposes.
if (typeof tinyfly === 'undefined') {
tinyfly = {};
}
/* Handles adding and removing loading animations for ajax calls */
tinyfly.loading = (function($) {
var defaults = {},
//--------------- ElementRef----------------------
@ViewChild('foo', {static: false}) foo: ElementRef;
@Component({
selector: 'sample',
template: `
@dev-sampsonorson
dev-sampsonorson / nx-structure-angular-nestjs.md
Created February 9, 2022 23:36 — forked from trungvose/nx-structure-angular-nestjs.md
Nx workspace structure for NestJS and Angular

Nx

https://nx.dev/

Nx is a suite of powerful, extensible dev tools to help you architect, test, and build at any scale — integrating seamlessly with modern technologies and libraries while providing a robust CLI, caching, dependency management, and more.

It has first-class support for many frontend and backend technologies, so its documentation comes in multiple flavours.

Principles

@dev-sampsonorson
dev-sampsonorson / palindrome.js
Created February 10, 2022 16:50
Recursive implementation to verify if a string is a palindrome
let input1 = 'kayak';
let input2 = 'vay ak';
let input3 = 'kay ak';
function isPalindrome(data) {
var charsToIgnore = /[.,'!?\- \"]/g;
var cleanData = data.replace(charsToIgnore, '').toLowerCase();;
if (cleanData.length === 1) return true;
if (cleanData.length === 2) return false;
@dev-sampsonorson
dev-sampsonorson / reverse-string.js
Created February 10, 2022 16:53
Recursive implementation to reverse a string
let input = "engineer at ProDevs";
const reverse = (data) => {
if (data.length === 1)
return data;
return data[data.length - 1] + reverse(data.slice(-data.length, -1));
}
console.log(reverse(input));
@dev-sampsonorson
dev-sampsonorson / decimal-to-binary.js
Created February 10, 2022 17:20
Recursive implementation to convert decimal to binary
const input1 = 233;
const input2 = 0;
const decimalToBinary = (quotient, remainder) => {
if (quotient === 0) {
return (remainder ?? '').toString();
}
return `${decimalToBinary(Math.floor(quotient / 2), quotient % 2)} ${(remainder ?? '').toString()}`;
}
@dev-sampsonorson
dev-sampsonorson / sum-natural-numbers.js
Created February 10, 2022 17:43
Recursive implementation to sum natural numbers
const input1 = 10;
const input2 = 1;
const input3 = 0;
const sumNaturalNumbers = (n) => {
if (n <= 1)
return n;
return n + sumNaturalNumbers(n - 1);
}
@dev-sampsonorson
dev-sampsonorson / binary-search.js
Created February 10, 2022 18:23
Recursive implementation of binary search
const input1 = [-1, 0, 1, 2, 3, 4, 7, 9, 10, 20];
// 0 1 2 3 4 5 6 7 8 9
const binarySearch = (array, left, right, target) => {
if (left > right)
return -1;
const mid = Math.floor((left + right) / 2);
if (target === array[mid])
@dev-sampsonorson
dev-sampsonorson / fib.js
Last active February 12, 2022 15:26
Recursive implementation of fibonacci (non-optimized)
const input1 = 7; // index
const input2 = 2; // index
const input3 = 3; // index
const fib = (index) => {
if ((index === 0) || (index === 1))
return index;
return fib(index - 2) + fib(index - 1);
}
@dev-sampsonorson
dev-sampsonorson / merge-sort.js
Created February 12, 2022 19:50
Recursive implementation of merge sort
const input1 = [-5, 20, 10, 3, 2, 0];
const merge = (data, start, min, end) => {
const temp = [];
let i = start, j = min + 1, x = 0;
while (i <= min && j <= end) {
if (data[i] > data[j]) {
temp.push(data[j++]);