Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Oliver Switzer oliverswitzer

🏠
Working from home
View GitHub Profile
@oliverswitzer
oliverswitzer / bookmarklet.js
Last active Aug 25, 2021
Small script that helps you locate hotspots from https://app.hotspotty.net/ in Google Earth. Just click the bookmarklet after navigating to the current selected hotspots "info" tab. To create bookmarklet, copy contents of bookmarklet.js, create a new empty bookmark, and paste into the bookmark. You can also make it yourself using this tool https…
View bookmarklet.js
javascript:(function()%7BopenGoogleEarthForHotspot()%3B%0Afunction earthUrl(lat%2C lng) %7B%0A return %60https%3A%2F%2Fearth.google.com%2Fweb%2Fsearch%2F%24%7Blat%7D%2C%24%7Blng%7D%60%3B%0A%7D%0A%0Aasync function openGoogleEarthForHotspot() %7B%0A const hotspotAddress %3D getHotspotAddress()%3B%0A const %7B lat%2C lng %7D %3D await getCoordinates(hotspotAddress)%3B%0A window.open(earthUrl(lat%2C lng))%3B%0A%7D%0A%0Aasync function getCoordinates(hotspotAddress) %7B%0A const res %3D await fetch(%0A %60https%3A%2F%2Fapi.helium.io%2Fv1%2Fhotspots%2F%24%7BhotspotAddress%7D%60%0A ).then((res) %3D> res.json())%3B%0A const %7B lng%2C lat %7D %3D res.data%3B%0A%0A return %7B lng%2C lat %7D%3B%0A%7D%0A%0Afunction getHotspotAddress() %7B%0A var xpath %3D "%2F%2F*%5Bcontains(text()%2C'Hotspot address')%5D"%3B%0A var matchingElement %3D document.evaluate(%0A xpath%2C%0A document%2C%0A null%2C%0A XPathResult.FIRST_ORDERED_NODE_TYPE%2C%0A null%0A ).singleNodeValue%3B%0A%0A return matchingElemen
View find_duplicate_BEAST_MODE.rb
def find_duplicate(int_array)
current_position = int_array[-1]
# Step 1: Get our cursor to the end of the int array list, so that we
# are guaranteed to be in a loop when we try to find the loop length
(int_array.length - 1).times do
current_position = int_array[current_position - 1]
end
loop_start_position = current_position
@oliverswitzer
oliverswitzer / bonus_merge_multiple_arrays.rb
Created May 20, 2020
Interview Cake Merge Multiple Sorted Arrays question
View bonus_merge_multiple_arrays.rb
# In order to win the prize for most cookies sold, my friend Alice and I are going to merge our Girl Scout Cookies orders and enter as one unit.
#
# Each order is represented by an "order id" (an integer).
#
# We have our lists of orders sorted numerically already, in arrays. Write a method to merge our arrays of orders into one sorted array.
#
# For example:
#
# my_array = [3, 4, 6, 10, 11, 15]
# alices_array = [1, 5, 8, 12, 14, 19]
View gist:7c1387e28e3a2791330fbf52fd109b16
# Intro
Writing changeable code: three different skills
- 1. understand OO design. Code that is easy to change IS well designed.
- 2. skilled at refactoring. Quote from Fowler
--> also maybe insert quote from Kent Beck:
"make the change easy (warning: this may be hard), then make the easy change"
- refactoring is how you morph code to accommodate new requirements. Prefactor vs refactor?
- 3. High value tests!
- Good tests don't need to be changed when you refactor.
@oliverswitzer
oliverswitzer / includes_module.rb
Last active Aug 29, 2015
A simple gist demonstrating how Ruby looks up module methods when they've been included in a class
View includes_module.rb
module Engine
def run
puts "GRRRRRRRRR"
end
end
class Vehicle
@oliverswitzer
oliverswitzer / mixpanel_api.js
Created Mar 27, 2014
A node script to get data from mixpanel API and output it to a CSV
View mixpanel_api.js
// mixpanel_export.js
// node modules
http = require('http');
Mixpanel = require('mixpanel');
md5 = require('MD5');
jsoncsv = require('jsoncsv');
fs = require('fs');
stringify = require('csv-stringify');
@oliverswitzer
oliverswitzer / example-data.json
Created Mar 27, 2014
The crappy JSON I got back from Mixpanel's API
View example-data.json
{"event":"first visit","properties":{"time":1389806707,"distinct_id":"14398a6d7eb77-0308ffb76-6e1a2776-384000-14398a6d7ec2b4","$browser":"Chrome","$city":"New York","$initial_referrer":"$direct","$initial_referring_domain":"$direct","$os":"Mac OS X","$region":"New York","date":{},"mp_country_code":"US","mp_lib":"web","url":"http://devolate.com/"}}
{"event":"first visit","properties":{"time":1389806825,"distinct_id":"14398a8a47aa-094bd1e04-6e1a2776-384000-14398a8a47b421","$browser":"Chrome","$city":"New York","$initial_referrer":"$direct","$initial_referring_domain":"$direct","$os":"Mac OS X","$region":"New York","date":{},"mp_country_code":"US","mp_lib":"web","url":"http://devolate.com/"}}
@oliverswitzer
oliverswitzer / barchart_update.rb
Created Mar 5, 2014
Updated working (sort of) barchart for BetaNYC Timeline Group!
View barchart_update.rb
<html>
<head>
<style>
.bar {
fill: steelblue;
}
.axis text {
font: 10px sans-serif;
@oliverswitzer
oliverswitzer / callingANodeModule.js
Created Feb 24, 2014
Example of calling my own custom module in Node
View callingANodeModule.js
var dirListModule = require('./dirListModule.js')
var dirPath = process.argv[2];
var extFilter = process.argv[3];
dirListModule(dirPath, extFilter, function(err, filteredList) {
filteredList.forEach(function(value) {
console.log(value);
});
});
@oliverswitzer
oliverswitzer / nonModuleDirList.js
Created Feb 24, 2014
An example of a script that will filter files with certain extensions in Node.js
View nonModuleDirList.js
// asynchDirList.js
var fs = require('fs'); //require node filesystem module
var path = require('path'); //require node path module (a couple of tools for reading path names)
var pathSupplied = process.argv[2];
var extFilter = process.argv[3];
function extension(element) {
var extName = path.extname(element);