Skip to content

Instantly share code, notes, and snippets.

@javi-aire
javi-aire / osx-for-hackers.sh
Created June 8, 2024 22:26 — forked from brandonb927/osx-for-hackers.sh
OSX for Hackers: Yosemite/El Capitan Edition. This script tries not to be *too* opinionated and any major changes to your system require a prompt. You've been warned.
#!/bin/sh
###
# SOME COMMANDS WILL NOT WORK ON macOS (Sierra or newer)
# For Sierra or newer, see https://github.com/mathiasbynens/dotfiles/blob/master/.macos
###
# Alot of these configs have been taken from the various places
# on the web, most from here
# https://github.com/mathiasbynens/dotfiles/blob/5b3c8418ed42d93af2e647dc9d122f25cc034871/.osx
@javi-aire
javi-aire / readForFree.js
Last active April 26, 2020 20:46
Because news orgs want people to pay to read things. In *this* pandemic?
function readForFree() {
// select html element
// set overflow to auto
document.documentElement.style.overflow = 'auto';
// LA times overlay id === reg-overlay
// set overlay to display: none !important
let overlayEl = document.getElementById('reg-overlay');
overlayEl.style.setProperty('display', 'none', 'important');
// 'remove' event listener from window
@javi-aire
javi-aire / findMaxLength.js
Created April 15, 2020 06:25
Problem 13/30 of LeetCode 30-day challenge
let findMaxLength = function(nums) {
const map = new Map();
map.set(0, -1);
let count = 0,
max = 0;
for(let i = 0; i < nums.length; i++) {
if(nums[i] === 0){
count--;
} else {
count++;
@javi-aire
javi-aire / lastStoneWeight.js
Last active April 14, 2020 02:44
Problem 12/30 of LeetCode 30-day challenge
let lastStoneWeight = function(stones) {
// 2 pointers & index for tracking in array
let pointer1 = 0;
let pointer2 = pointer1 + 1;
let index = pointer2 + 1;
let weight1, weight2;
// reset pointers and weights
function resetValues() {
// reset pointers and weights
@javi-aire
javi-aire / diameterOfBinaryTree.js
Last active April 13, 2020 04:26
Problem 11/30 of LeetCode 30-day challenge
/**
* Definition for a binary tree node.
* function TreeNode(val) {
* this.val = val;
* this.left = this.right = null;
* }
*/
/**
* @param {TreeNode} root
* @return {number}
@javi-aire
javi-aire / MinStack.js
Created April 12, 2020 23:22
Problem 10/30 of LeetCode 30-day challenge
class MinStack {
constructor() {
this.items = [];
}
push(item) {
this.items.push(item);
}
pop() {
@javi-aire
javi-aire / backspaceCompare.js
Last active April 11, 2020 05:37
Problem 9/30 of LeetCode 30-day challenge
let backspaceCompare = function(S, T) {
let string_s = S.split('').reduce((acc, char, index) => {
if(char === '#') {
acc.pop();
} else {
acc.push(char);
}
return acc;
}, []).join('');
@javi-aire
javi-aire / middleNode.js
Created April 9, 2020 01:07
Problem 8/30 of LeetCode 30-day challenge
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
let middleNode = function(head) {
let length = 1;
@javi-aire
javi-aire / groupAnagrams.js
Created April 8, 2020 02:44
Problem 6/30 of LeetCode 30-day challenge
let groupAnagrams = function(strs) {
let result = {};
for(let i = 0; i < strs.length; i++) {
let word = strs[i];
// sort the letters, join them together
let sortedWord = word.split('').sort().join();
if(!result[sortedWord]){
// if sortedWord is not in object
// set sorted as key and orig word as array value
@javi-aire
javi-aire / countElements.js
Created April 7, 2020 23:07
Problem 7/30 of LeetCode 30-day challenge
let countElements = function(arr) {
// returning a counter of times a number x + 1
// is found in an array
let count = 0;
// need storage to keep track of x + 1 frequency
let storage = {};
for(let num of arr){
// if a number x + 1 is in the array
if(arr.indexOf(num + 1) > -1) {