Skip to content

Instantly share code, notes, and snippets.

View clarketm's full-sized avatar
🐍
Programming

Travis Clarke clarketm

🐍
Programming
View GitHub Profile
@clarketm
clarketm / get_oauth2_token.py
Last active August 30, 2023 19:42
How to get Google OAuth 2.0 access token in console using the Python API
#!/usr/bin/env python
'''
This script will attempt to open your webbrowser,
perform OAuth 2.0 authentication and print your access token.
To install dependencies from PyPI:
$ pip install oauth2client
Then run this script:
@clarketm
clarketm / gist:861371f50d1f5fad09568490834315e5
Created August 18, 2016 17:30 — forked from tonymtz/gist:d75101d9bdf764c890ef
Uninstall nodejs from OSX Yosemite
# 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 September 26, 2016 03:23 — forked from anonymuse/ch_04_picture_grid.py
Automate the Boring Stuff with Python -- Chapter 04 -- Character Picture Grid
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 / cyclicRotation.js
Last active June 16, 2021 15:38
Cyclic Rotation (JavaScript)
function cyclicRotation(array, times) {
var rotatedArray = array;
while (times > 0) {
var currentArray = rotatedArray.slice();
for (var i = 0; i < currentArray.length; i++) {
rotatedArray[(i+1)%currentArray.length] = currentArray[i];
}
times--;
@clarketm
clarketm / largestBinaryGap.js
Last active October 12, 2022 12:13
Largest Binary Gap (JavaScript)
function largestBinaryGap(num) {
var bin = Math.abs(num).toString(2),
finalMax = 0,
currentMax;
for (var i = 0; i < bin.length; i++) {
currentMax = 0;
while (bin[i] === "0") {
++currentMax && ++i;
}
@clarketm
clarketm / The Technical Interview Cheat Sheet.md
Created May 24, 2016 16:40 — 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.

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 April 8, 2017 06:01
Binary Search (JavaScript)
function binarySearch(array, target) {
var startIndex = 0,
stopIndex = array.length - 1,
middle,
count = 0;
while (startIndex < stopIndex) {
count++;
middle = ~~((stopIndex + startIndex) / 2);
@clarketm
clarketm / FindMinBinarySearch.js
Created May 24, 2016 01:31
Find Min Binary Search (JavaSript)
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 / ransomNoteProblemES6.js
Last active May 24, 2016 01:29
Ransom Note Problem (ES6)
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 / ransomNoteProblem.js
Last active August 12, 2016 04:26
Ransom Note Problem (JavaScript)
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);