Skip to content

Instantly share code, notes, and snippets.

View tko22's full-sized avatar
🐣

Timothy Ko tko22

🐣
View GitHub Profile

Helpful Python snippets for algorithm interviews

Intervals

Merge

def merge_overlap(a, b):
    return [min(a[0], b[0]), max(a[1], b[1])]

Overlap?

@tko22
tko22 / understanding-backend.md
Last active June 16, 2018 23:25
understanding backend with prior frontend experience

Understanding Backend

before the rise of SPA (single page applications), web applications were rendered server-side. Let's go through how that would work:

  • you visit a url, such as https://url.com/ or https://url.com/about or https://url.com/blog. /, /about, blog are all examples of "paths" or endpoints
  • based on the path, the server-through a web framework (django, flask, express.js, ruby on rails, etc)-will send out certain data based on that path. That data is usually a html & css files along with Javascript.
  • But you want an interactive website but vanilla Javascript was a little too much to write. Enter JQuery. JQuery was a popular library that made manipulating the DOM a lot easier. You would basically choose a certain element in the DOM (based on a HTML class, id, tag, etc.) and do something with it and you could also act on it if a certain event happens (eg button click). If you'd like to make a request, you would use AJAX, which is an abstraction of making an HTTP request (Now,
@tko22
tko22 / things.md
Last active May 3, 2020 00:05
Useful Things I've encountered and don't know where to put

aliases to checkout a specific PR's branch

Copy/paste each line (one at a time) to gitbash or terminal window.

git config --global --add alias.pr '!f() { git fetch -fu ${2:-upstream} refs/pull/$1/head:pr/$1 && git checkout pr/$1; }; f'

and

git config --global --add alias.pr-clean '!git checkout master ; git for-each-ref refs/heads/pr/* --format="%(refname)" | while read ref ; do branch=${ref#refs/heads/} ; git branch -D $branch ; done'Once created the aliases are used as shown below.

To pull a pull request: git pr to use the example above git pr 123

var Voting = artifacts.require("Voting")
module.exports = function(deployer) {
deployer.deploy(Voting)
}
@tko22
tko22 / index.html
Created January 27, 2018 06:28
Ethereum Voting DApp
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Ethereum Voting Dapp</title>
<!-- Bootstrap -->
@tko22
tko22 / app.js
Created January 27, 2018 05:57
Ethereum Voting Decentralized Application
// import CSS. Webpack with deal with it
import "../css/style.css"
// Import libraries we need.
import { default as Web3} from "web3"
import { default as contract } from "truffle-contract"
// import and assign compiled contract data to variable
import votingArtifacts from "../../build/contracts/Voting.json"
var VotingContract = contract(votingArtifacts)
// When the page loads, we create a web3 instance and set a provider. We then set up the app
window.addEventListener("load", function() {
// Is there an injected web3 instance?
if (typeof web3 !== "undefined") {
console.warn("Using web3 detected from external source like Metamask")
// If there is a web3 instance(in Mist/Metamask), then we use its provider to create our web3object
window.web3 = new Web3(web3.currentProvider)
} else {
console.warn("No web3 detected. Falling back to http://localhost:9545. You should remove this fallback when you deploy live, as it's inherently insecure. Consider switching to Metamask for development. More info here: http://truffleframework.com/tutorials/truffle-and-metamask")
// fallback - use your fallback strategy (local node / hosted node + in-dapp id mgmt / fail)
@tko22
tko22 / App.js
Last active June 14, 2018 03:33
Voting DApp for Medium Post
// import CSS. Webpack with deal with it
import "../css/style.css"
// Import libraries we need.
import { default as Web3} from "web3"
import { default as contract } from "truffle-contract"
// get build artifacts from compiled smart contract and create the truffle contract
import votingArtifacts from "../../build/contracts/Voting.json"
var VotingContract = contract(votingArtifacts)
@tko22
tko22 / Voting.sol.js
Last active January 3, 2019 18:48
Voting DApp Medium Post
pragma solidity ^0.4.18;
// written for Solidity version 0.4.18 and above that doesnt break functionality
contract Voting {
// an event that is called whenever a Candidate is added so the frontend could
// appropriately display the candidate with the right element id (it is used
// to vote for the candidate, since it is one of arguments for the function "vote")
event AddedCandidate(uint candidateID);
// describes a Voter, which has an id and the ID of the candidate they voted for
@tko22
tko22 / The Technical Interview Cheat Sheet.md
Last active January 25, 2018 04:32 — forked from tsiege/The Technical Interview Cheat Sheet.md
This is my technical interview cheat sheet. Feel free to fork it or do whatever you want with it. PLEASE let me know if there are any errors or if anything crucial is missing. I will add more links soon.

Studying for a Tech Interview Sucks, so Here's a Cheat Sheet to Help

This list is meant to be a both a quick guide and reference for further research into these topics. It's basically a summary of that comp sci course you never took or forgot about, so there's no way it can cover everything in depth. It also will be available as a gist on Github for everyone to edit and add to.

Data Structure Basics

Array

Definition:

  • Stores data elements based on an sequential, most commonly 0 based, index.
  • Based on tuples from set theory.