Skip to content

Instantly share code, notes, and snippets.

Avatar
🐍
Programming

Travis Clarke clarketm

🐍
Programming
View GitHub Profile
@clarketm
clarketm / findMinArray.js
Created May 23, 2016
Find Min Array (JavaScript)
View findMinArray.js
function findMin(array) {
var min = array[0],
count = 0;
for (var i = 1; i < array.length; i++, count++) {
if (array[i] < min) {
min = array[i];
}
}
console.log(count + " iterations");
@clarketm
clarketm / ransomNoteProblemES6.js
Last active May 24, 2016
Ransom Note Problem (ES6)
View ransomNoteProblemES6.js
function isRansomNotePossible(newsArticle, ransomNote) {
let availableChars = new Map();
for (let r of newsArticle) {
let asciiCode = newsArticle.charCodeAt(r);
availableChars.set(asciiCode, (availableChars.get(asciiCode) || 0) + 1);
}
for (let r of ransomNote) {
let asciiCode = ransomNote.charCodeAt(r);
@clarketm
clarketm / FindMinBinarySearch.js
Created May 24, 2016
Find Min Binary Search (JavaSript)
View FindMinBinarySearch.js
function findMinBinarySearch(array) {
var left = 0, // index of first element
right = array.length - 1, // index of last element.
mid, // midpoint
count = 0;
while (array[left] > array[right]) {
count++;
mid = ~~((left + right) / 2); // math.floor of the midpoint
if (array[mid] > array[right]) {
@clarketm
clarketm / ransomNoteProblem.js
Last active Aug 12, 2016
Ransom Note Problem (JavaScript)
View ransomNoteProblem.js
function isRansomNotePossible(newsArticle, ransomNote) {
var availableChars = {};
for (var r = 0; r < newsArticle.length; r++) {
var asciiCode = newsArticle.charCodeAt(r);
availableChars[asciiCode] = (availableChars[asciiCode] || 0) + 1
}
for (var r = 0; r < ransomNote.length; r++) {
var asciiCode = ransomNote.charCodeAt(r);
View gist:861371f50d1f5fad09568490834315e5
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@clarketm
clarketm / ch_04_picture_grid.py
Last active Sep 26, 2016 — forked from anonymuse/ch_04_picture_grid.py
Automate the Boring Stuff with Python -- Chapter 04 -- Character Picture Grid
View ch_04_picture_grid.py
grid = [['.', '.', '.', '.', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['O', 'O', 'O', 'O', 'O', '.'],
['.', 'O', 'O', 'O', 'O', 'O'],
['O', 'O', 'O', 'O', 'O', '.'],
['O', 'O', 'O', 'O', '.', '.'],
['.', 'O', 'O', '.', '.', '.'],
['.', '.', '.', '.', '.', '.']]
@clarketm
clarketm / The Technical Interview Cheat Sheet.md
Created May 24, 2016 — forked from TSiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.
View The Technical Interview Cheat Sheet.md

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

###Array ####Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.
@clarketm
clarketm / binarySearch.js
Last active Apr 8, 2017
Binary Search (JavaScript)
View binarySearch.js
function binarySearch(array, target) {
var startIndex = 0,
stopIndex = array.length - 1,
middle,
count = 0;
while (startIndex < stopIndex) {
count++;
middle = ~~((stopIndex + startIndex) / 2);
@clarketm
clarketm / Effect.js
Created Apr 13, 2017 — forked from brentvatne/Effect.js
redux-saga alternative with async/await?
View Effect.js
/**
* @providesModule Effects
* @flow
*/
import { Linking } from 'react-native';
import AppDataApi from 'AppDataApi';
import Actions from 'Actions';
import ActionTypes from 'ActionTypes';
@clarketm
clarketm / detectBrowserLanguage.js
Created Apr 4, 2017 — forked from leipert/detectBrowserLanguage.js
Detect browser language in javascript (utilizing lodash)
View detectBrowserLanguage.js
// These window.navigator contain language information
// 1. languages -> Array of preferred languages (eg ["en-US", "zh-CN", "ja-JP"]) Firefox^32, Chrome^32
// 2. language -> Preferred language as String (eg "en-US") Firefox^5, IE^11, Safari,
// Chrome sends Browser UI language
// 3. browserLanguage -> UI Language of IE
// 4. userLanguage -> Language of Windows Regional Options
// 5. systemLanguage -> UI Language of Windows
var browserLanguagePropertyKeys = ['languages', 'language', 'browserLanguage', 'userLanguage', 'systemLanguage'];