Skip to content

Instantly share code, notes, and snippets.

View jpoechill's full-sized avatar

Po Rith jpoechill

View GitHub Profile
@jpoechill
jpoechill / clientside-webscraper.js
Created August 16, 2019 20:52
A simple client-side web scraper setup.
import axios from 'axios'
// a proxy server is not always needed for all sites
// though in some cases, sites will restrict access to those that are not same-origin
// in such case, proxy servers can be used to bypass, as seen here using https://cors-anywhere.herokuapp.com/.
axios.get('https://cors-anywhere.herokuapp.com/https://designboom.com', { crossdomain: true }).then((response) => {
// returns raw html which can be used subsequently as DOM nodes
console.log(response.data)
@jpoechill
jpoechill / stacksnQueues.js
Created June 5, 2017 06:04
Simple stacks and Queues with Javascript
var stack = []
stack.push(1)
console.log(stack)
stack.pop()
console.log(stack)
var queue = []
@jpoechill
jpoechill / myLinkedLists.js
Created June 5, 2017 05:11
Customized Linked Lists with Javascript
// From ThatJSDude
function linkedList () {
this.head = null
this.length = 0
}
linkedList.prototype.push = function (val) {
var node = {
value: val,
@jpoechill
jpoechill / linkedList-02.js
Created June 5, 2017 04:25
Linked Lists with JS
// from Tutsplus, https://code.tutsplus.com/articles/data-structures-with-javascript-singly-linked-list-and-doubly-linked-list--cms-23392
function Node(data) {
this.data = data;
this.next = null;
}
function SinglyList() {
this._length = 0;
this.head = null;
@jpoechill
jpoechill / linkedList-01.js
Created June 5, 2017 03:57
Linked Lists with JS
// From ThatJSDude, http://thatjsdude.com/interview/linkedList.html#singlyLinkedList
function linkedList () {
this.head = null
}
linkedList.prototype.push = function (val) {
var node = {
value: val,
next: null
@jpoechill
jpoechill / diagonal-bgs.css
Created June 3, 2017 21:36
Udacity's hp-css for diagonal bgs
.contain::before {
content: '';
width: 100%;
height: 660px;
z-index: -1000;
background: linear-gradient(to bottom right, #F7F7F7, #EAFBFF);
transform-origin: left bottom;
position: absolute;
top: 0;
left: 0;
@jpoechill
jpoechill / mergedMeetings.js
Created May 30, 2017 00:02
Merged Meetings via. Interview Cake
// Final solution
function mergeRanges (meetings) {
// sort by start time
var sortedMeetings = meetings.slice().sort(function (a, b) {
return a.startTime > b.startTime ? 1: -1
})
// initialize meetings with first from sorted meetings
var mergedMeetings = [sortedMeetings[0]]
@jpoechill
jpoechill / getProductsOfAllIntsExceptAtIndex.js
Last active May 25, 2017 04:58
Product of All Other Numbers via. InterviewCake
function getProductsOfAllIntsExceptAtIndex (arr) {
var productsOfArr = []
for (var i = 0; i < arr.length; i++) {
var clone = arr.slice(0)
var removed = clone.splice(i, 1)
productsOfArr.push(getProductOfArr(clone));
}
@jpoechill
jpoechill / appleStocks.js
Last active May 25, 2017 04:15
Apple Stocks via. InterviewCake
function getMaxProfit(stockPrices) {
var allPurchases = {}
var allPurchasesArr = []
for (var i = 0; i < (stockPrices.length); i++) {
var stockClone = stockPrices.slice(0)
var currRemoved = stockClone.splice(0, i+1)
var maxStockRight = Math.max(...stockClone)
allPurchases[stockPrices[i]] = stockPrices[i] - maxStockRight
@jpoechill
jpoechill / repeatedDNASequences
Created May 24, 2017 04:22
repeatedDNASequences via. CodeFights
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T. In research, it can be useful to identify repeated sequences within DNA.
Write a function to find all the 10-letter sequences (substrings) that occur more than once in a DNA molecule s, and return them in lexicographical order. These sequences can overlap.
Example
For s = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT", the output should be
repeatedDNASequences(s) = ["AAAAACCCCC", "CCCCCAAAAA"].
Input/Output