Skip to content

Instantly share code, notes, and snippets.

View rebolyte's full-sized avatar

James Irwin rebolyte

View GitHub Profile
@rebolyte
rebolyte / typescript-intro.md
Last active May 13, 2020 23:17
TypeScript basic intro

TypeScript intro

James Irwin
7-Jun-2018

TypeScript is a typed superset of JavaScript. All JavaScript is valid TypeScript, and TS transpiles to JS to run in browsers (much like Babel transpiles ES6+ to ES5). In transpilation, all types are stripped out; you get type-checking at compile-time only (but run-time type-checking is needed much less because of it). It is developed by Microsoft, powers apps you know like VS Code, and is in use at companies like Lyft, Reddit, and Slack.

Definition files

TypeScript lets you use existing JavaScript libraries in a strongly-typed manner by providing type definition files, which are separate files that annotate a given library's API. When you go to import lodash, you will likely also want to import @typings/lodash, which will install a lodash/index.d.ts file in your dependencies. So

@rebolyte
rebolyte / case-convert.js
Created February 13, 2017 16:14
Change a string from camelCase to kebab-case or snake_case and vice versa
'use strict';
let DASH_LOWERCASE_REGEX = /-([a-z])/g;
let UNDERSCORE_LOWERCASE_REGEX = /_([a-z])/g;
let UPPERCASE_REGEX = /([A-Z])/g;
// func argument to .replace receives:
// 1) the matched substring
// 2) nth parenthesized substr match (i.e. if the pattern has any `()` group matches,
// those will be passed as the next args)
@rebolyte
rebolyte / index.html
Created October 2, 2017 18:31
Shopping cart exercise
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Make tacos in the browser!">
<meta name="keywords" content="taco, tacos, truck, austin">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Shopping cart</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.5.3/css/bulma.min.css">
<style type="text/css">
@rebolyte
rebolyte / index.html
Last active April 12, 2019 01:14
stopwatch exercise
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="Cross-timezone stopwatch">
<meta name="keywords" content="time, watch, stopwatch, clock, timer">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Stopwatch</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.5.3/css/bulma.min.css">
<style type="text/css">
@rebolyte
rebolyte / jlin.py
Last active November 12, 2018 17:26
def my_reduce(func, lst):
#base case
if (len(lst) == 1):
return lst[0]
#recurse
temp = func(lst[0], lst[1])
return my_reduce(func, [temp] + lst[2:])
// Promise.resolve(ids).then(ids => {
// return ids.reduce((cur, next) => {
// return cur.then(() => {
// return doThingThatReturnsPromise(next);
// });
// }, Promise.resolve());
// }).then(() => {
// console.log('all done');
// }).catch(err => {
// console.error(err);
@rebolyte
rebolyte / matching-brackets.js
Last active October 4, 2017 17:00
matching brackets
// https://www.reddit.com/r/javascript/comments/4eb61r/interview_exercise_feedback/
function isBalanced(str) {
var dict = {
'{': '}',
'(': ')',
'[': ']'
};
var stack = [];
for (var i = 0; i < str.length; i++) {
@rebolyte
rebolyte / polish.js
Last active September 29, 2017 20:08
Evaluate a string in Reverse Polish Notation and output the result.
// https://codegolf.stackexchange.com/questions/221/reverse-polish-notation
'use strict';
// let s = '-4 5 +';
// let s = '5 2 /';
// let s = '5 2.5 /';
// let s = '4 2 5 * +';
// let s = '5 1 2 + 4 * 3 - +';
let s = '4 2 5 * + 1 3 2 * + /';
@rebolyte
rebolyte / abc123.js
Last active September 29, 2017 18:02
print alphabet using char codes
function range(x, y) {
if (typeof y === 'undefined') {
y = x;
x = 0;
}
let out = [];
while (x < y) {
out.push(x++);
}
return out;
@rebolyte
rebolyte / gist:ba25c16c25d3f87ecf3b
Created November 2, 2015 22:17
nvm .tar.xz error
$ nvm install 4.0.0
Downloading https://nodejs.org/dist/v4.0.0/node-v4.0.0-darwin-x86.tar.xz...
######################################################################## 100.0%
WARNING: checksums are currently disabled for node.js v4.0 and later
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
Binary download failed, trying source.
######################################################################## 100.0%
Checksums empty
tar: Unrecognized archive format