Skip to content

Instantly share code, notes, and snippets.

@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

// 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 / UserAlerts.js
Last active May 13, 2020 23:18
Webpack script-loader problems
if (Ext4 === undefined) { window.Ext4 = Ext; }
Ext4.define('UserAlerts', (function () {
return {
extend: 'WidgetBase',
height:40,
data: {},
cls: 'UserAlerts',
listeners: {
@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 / 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 / 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:])
@rebolyte
rebolyte / store.js
Created February 23, 2017 16:06
keep properties private in a closure with a getter/setter proxy
'use strict';
// keeping things private
let store = (() => {
let debug = true;
let state = {
isLoggedIn: false,
user: {}
};
@rebolyte
rebolyte / dydb-get-items.js
Created February 22, 2017 15:52
wrapper to get a list of items from DynamoDB
function getItems(opts) {
passMuster(opts, {
table: 'string',
hashkey: 'string',
items: 'array',
_optional: {
rangekey: 'string',
rangeval: 'string',
project: 'string'
}
@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 / 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;