Skip to content

Instantly share code, notes, and snippets.

@erosenberg
erosenberg / rename_filetype.sh
Created December 15, 2019 16:50
Create directories from filenames and move the files into those directories, based on file type.
read -p "Please enter a file type: " filetype
read -p "Please enter a directory: " filesdir
if [ -z $filetype ]
then
echo "$filetype is empty. Please retry."
exit 2
fi
if [ ! -d $filesdir ]
var lengthOfLongestSubstring = function(s) {
// input: string (s)
// output: num (longest non consecutive string length)
const sArr = s.trim().split('');
const map = new Map();
let uniqueStr = '';
let uniqueStrMax = 0;
for (var i = 0; i < sArr.length; i++) {
@erosenberg
erosenberg / distributeCandies.js
Created October 1, 2017 17:09
HashTable in ES6 for Leetcode #575
const distributeCandies = function(candies) {
if (candies.length % 2 !== 0) return candies;
candies = candies.sort(function(a, b) { return a - b; });
const half = candies.length / 2;
let dict = new Map();
let maxValue = Object.keys(dict).length;
candies.forEach((candy, i) => {
if (!dict.has(candy)) {
dict.set(candy, 1);
@erosenberg
erosenberg / binarySearch.js
Last active October 1, 2017 15:52
Binary Search with Recursion
let moves = 0;
const findItem = (arr, target) => {
if (!Array.isArray(arr)) return arr;
moves++;
const midIndex = Math.floor(arr.length / 2);
const midValue = arr[midIndex];
if (target === midValue) {
return midValue;
@erosenberg
erosenberg / TransitionHook.jsx
Created June 8, 2015 03:50
TransitionHook Class
import { object } from 'react';
'use strict';
class TransitionHook extends React.Component {
constructor(props) {
super(props);
this.router = this.context.router;