Skip to content

Instantly share code, notes, and snippets.

View shalomsam's full-sized avatar
👋

Shalom Sam shalomsam

👋
View GitHub Profile
@shalomsam
shalomsam / directives.js
Last active October 31, 2017 10:42
Useful Angular Directives
angular.module('cocoApp')
.directive('goBack', function () {
return {
restrict: 'A',
link: function (scope, element, attr) {
element.on('click', function () {
history.back();
scope.$apply();
})
}
@shalomsam
shalomsam / mixins.scss
Created August 9, 2018 09:42
Useful Sass mixins
@import "~node_modules/bootstrap/scss/_variables.scss";
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
@mixin transition($prop) {
@shalomsam
shalomsam / morse-code-possibilities.js
Created February 13, 2019 06:17
Given 3 morse code characters determines the letter associated with it. Any of the morse can be substituted for ? and this code will respond with possibilities
function possibilities (signals) {
var atoms = {
".": "E",
"-": "T",
"I": {
".": "S",
"-": "U"
},
"A": {
".": "R",
@shalomsam
shalomsam / MinDeletions.ts
Created June 27, 2021 19:34
Minimum Deletions to Make Character Frequencies Unique
type Frequency = { [key: string]: number };
function minDeletions(s: string): number {
const stringArr: string[] = s.split('');
// Get the character frequencies
const freq: Frequency = {};
stringArr.map((str) => {
freq[str] = Number(freq?.[str] || 0) + 1;
});
@shalomsam
shalomsam / README.md
Created June 28, 2021 02:21
Given a string, what is the minimum number of adjacent swaps required to convert a string into a palindrome. If not possible, return -1.

Given a string, what is the minimum number of adjacent swaps required to convert a string into a palindrome. If not possible, return -1.

Example 1:

Input: "mamad"
Output: 3

Example 2:

Arrays: move zeros to the left Given an integer array, move all elements that are 0 to the left while maintaining the order of other elements in the array. The array has to be modified in-place.

Example:

Given - [1, 10, 20, 0, 59, 63, 0, 88, 0]

Result - [0, 0, 0, 1, 10, 20, 59, 63, 88]
@shalomsam
shalomsam / README.md
Created September 16, 2021 21:04
Next Permutation

Next Permutation (Leetcode, Medium - Hard) ***

https://leetcode.com/problems/next-permutation/

Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.

If such an arrangement is not possible, it must rearrange it as the lowest possible order (i.e., sorted in ascending order).

The replacement must be in place and use only constant extra memory.

@shalomsam
shalomsam / tail.js
Created November 10, 2021 01:46
Shell Tail command in Node.js
#!/usr/bin/env node
let fs = require('fs');
let path = require('path');
let args = process.argv.slice(2);
//console.log(args);
let parseArgs = (args) => {
let parsed = {};