Skip to content

Instantly share code, notes, and snippets.

View primaryobjects's full-sized avatar

Kory Becker primaryobjects

View GitHub Profile
@primaryobjects
primaryobjects / visited.js
Created January 17, 2017 14:14
Remembering visited urls (i.e., in a web crawler) with optimized memory storage for urls within array. Demo at http://jsbin.com/rogigobafi/edit?js,console
/*
Example of solving the MillionGazillion Web Crawler problem:
A web crawler is storing visited urls in an array, but memory is running low on the computer, due to the array size growing too large.
A solution is to compress the urls by replacing common portions with single character replacements and by breaking up the domain
and path of urls, to store paths on the same domain, without repeating the domain portion of the url. If a web site has 1,000 pages,
only 1 domain entry will be added to the array, and 1,000 paths will be added under it, saving the space from repeating the entire url.
This test shows a savings of 74% memory usage.
*/
var visited1 = {};
@primaryobjects
primaryobjects / abinarytree.png
Last active February 6, 2017 16:52
Binary search tree BST in JavaScript with pre-order traversal.. Demo at http://jsbin.com/vukudixacu/1/edit?js,console
abinarytree.png
@primaryobjects
primaryobjects / intro.txt
Last active February 18, 2020 13:56
The Parking Lot Problem: A Google Interview Question for Software Engineers.
This question was found at https://www.careercup.com/question?id=5750868554022912
Suppose a row of parking lot with n spots, one of them is empty and n-1 spots are occupied with cars.
Only one operation is allowed: move one car from its position to the empty spot.
Given a initial order of cars and a final order, output steps needed to convert initial order to final oder with that operation.
Solution
========
This type of planning problem can be solved using the AI planning algorithm STRIPS.
@primaryobjects
primaryobjects / index.js
Created January 6, 2017 20:40
Example of displaying an image in an Amazon Alexa home card.
var alexa = require('alexa-app');
var app = new alexa.app('myapp');
app.intent('showCard', {
'slots': {},
'utterances': [ 'show card' ]
},
function(req, res) {
// Show home card in Alexa app.
{
"name": "alexa-app-server",
"version": "2.2.4",
"description": "A web server module for Alexa (Amazon Echo) skills ..",
"main": "index.js",
"author": "Author Name",
"dependencies": {
"alexa-app": "^2.1.0",
"bluebird": "^2.9.34",
"body-parser": "~1.0.1",
@primaryobjects
primaryobjects / overlapRect.R
Last active December 24, 2016 21:42
[2016-12-22] Challenge #296 [Intermediate] Intersecting Area Of Overlapping Rectangles
#
# [2016-12-22] Challenge #296 [Intermediate] Intersecting Area Of Overlapping Rectangles
# You need to find the area that two rectangles overlap. The section you need to output the area of would be the blue lined section here: http://i.imgur.com/brZjYe5.png If the two rectangles do not overlap, the resultant area should be NA.
# https://www.reddit.com/r/dailyprogrammer/comments/5jpt8v/20161222_challenge_296_intermediate_intersecting/
# Demo at http://www.r-fiddle.org/#/fiddle?id=VL0FGiNT&version=3
#
# by Kory Becker
# http://primaryobjects.com
#
@primaryobjects
primaryobjects / paypal.txt
Last active May 26, 2026 16:02
Bypass the annoying PayPal interstitial ad to login directly to your account. Simply append the following to the PayPal.com domain: /us/cgi-bin/webscr?cmd=_account
https://paypal.com/us/cgi-bin/webscr?cmd=_account
@primaryobjects
primaryobjects / letterbyletter.R
Created December 17, 2016 02:12
[2016-12-12] Challenge #295 [Easy] Letter by letter
#
# [2016-12-12] Challenge #295 [Easy] Letter by letter
# hange the a sentence to another sentence, letter by letter. The sentences will always have the same length.
# https://www.reddit.com/r/dailyprogrammer/comments/5hy8sm/20161212_challenge_295_easy_letter_by_letter/
# Demo at http://www.r-fiddle.org/#/fiddle?id=gdBm15yC
#
# by Kory Becker
# http://primaryobjects.com
#
var appServer = require('./index');
appServer.start({ port: process.env.PORT || 3000, debug: true });
document.querySelector("iframe[name=\'view_frame\']").contentDocument.querySelector("iframe[name=\'iframe_model\']").contentDocument.querySelector("input[type=submit]")