Skip to content

Instantly share code, notes, and snippets.

Avatar

Po Rith jpoechill

View GitHub Profile
@jpoechill
jpoechill / clientside-webscraper.js
Created Aug 16, 2019
A simple client-side web scraper setup.
View clientside-webscraper.js
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 Jun 5, 2017
Simple stacks and Queues with Javascript
View stacksnQueues.js
var stack = []
stack.push(1)
console.log(stack)
stack.pop()
console.log(stack)
var queue = []
@jpoechill
jpoechill / myLinkedLists.js
Created Jun 5, 2017
Customized Linked Lists with Javascript
View myLinkedLists.js
// 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 Jun 5, 2017
Linked Lists with JS
View linkedList-02.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 Jun 5, 2017
Linked Lists with JS
View linkedList-01.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 Jun 3, 2017
Udacity's hp-css for diagonal bgs
View diagonal-bgs.css
.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
Merged Meetings via. Interview Cake
View mergedMeetings.js
// 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
Product of All Other Numbers via. InterviewCake
View getProductsOfAllIntsExceptAtIndex.js
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
Apple Stocks via. InterviewCake
View appleStocks.js
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
repeatedDNASequences via. CodeFights
View repeatedDNASequences
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
You can’t perform that action at this time.