Skip to content

Instantly share code, notes, and snippets.

View vontell's full-sized avatar
🏙️
Philadelphia

Aaron Vontell vontell

🏙️
Philadelphia
View GitHub Profile
@vontell
vontell / chip_background.xml
Created January 27, 2018 16:15
002 Chip Background
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="0dp">
<solid android:color="#E0E0E0"/>
<corners
android:bottomRightRadius="16dp"
android:bottomLeftRadius="16dp"
android:topLeftRadius="16dp"
android:topRightRadius="16dp"/>
</shape>
@vontell
vontell / ic_close.xml
Last active January 27, 2018 16:06
002 Close Icon Drawable
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="#98000000" android:pathData="M12,2C17.53,2 22,6.47 22,12C22,17.53 17.53,22 12,22C6.47,22 2,17.53 2,12C2,6.47 6.47,2 12,2M15.59,7L12,10.59L8.41,7L7,8.41L10.59,12L7,15.59L8.41,17L12,13.41L15.59,17L17,15.59L13.41,12L17,8.41L15.59,7Z" />
</vector>
@vontell
vontell / 001 Example.js
Created January 16, 2018 20:25
001 Example
function startServer() {
loadValidWords(function() {
console.log("Available words: " + words.length);
var newURL = shortenURL("https://medium.com/365-days-of-coding");
console.log("New URL: " + newURL);
var oldURL = getURLFromShortened(newURL);
console.log("Old URL: " + oldURL);
removeShortenedURL(newURL);
@vontell
vontell / 001 Remove Record.js
Created January 16, 2018 20:22
001 Remove Record
/**
* Deletes the shortened URL record associated with the given shortenedURL,
* returning the short URL word used back to the word pool.
* shortenedURL - A shortened URL generated by this program instance
*/
function removeShortenedURL(shortenedURL) {
var word = shortenedURL.replace(baseDomain, "");
delete urlDictionary[word];
words.push(word);
}
@vontell
vontell / 001 Get Url.js
Created January 16, 2018 20:19
001 Get Url
/**
* Returns the saved URL given the shortened URL (generated by this program)
* shortenedURL - A shortened URL generated by this program instance
*/
function getURLFromShortened(shortenedURL) {
return urlDictionary[shortenedURL.replace(baseDomain, "")];
}
@vontell
vontell / 001 Shorten URL.js
Created January 16, 2018 20:07
001 Shorten URL
// Predefined constants
const baseDomain = "https://mywebsite.com/"
// Cached global variables
var urlDictionary = {}
/**
* Returns a shortened version of the given `url`, which is saved for later
* retrieval.
* url - The url to shorten
@vontell
vontell / 001 Load Valid Words.js
Last active January 16, 2018 19:58
001 Load Valid Words
// Predefined constants
const wordFilePath = "resources/google-10000-english-usa-no-swears.txt";
const minWordLength = 3;
const maxWordLength = 6;
// Cached global variables
var words = []
/**
* Loads a list of words from the file at `wordFilePath`, which should contain
@vontell
vontell / 001 Module Dependencies.js
Last active January 16, 2018 19:55
001 Module Dependencies
// Module dependencies
const fs = require('fs'); // Used for opening the word file
const lineReader = require('readline'); // Used for buffering the file line by line
var result = document.evaluate("//text()", document.body, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
for (var i = 0; i < result.snapshotLength; ++i) {
var node = result.snapshotItem(i);
if ((node.textContent+"").match(/\w/)&&node.parentNode.nodeName != "STYLE") {
node.textContent = node.textContent.replace(/[A-Z0-9]/g, "X").replace(/[a-z]/g, "x");
}
}
void 0
data = [ 2, 4, 6 ]
total = 0
average = 0
n = 0
for value in data:
n += 1
total += value
average = total / n
print "average:", average