Skip to content

Instantly share code, notes, and snippets.

View AlexJWayne's full-sized avatar

Alex Wayne AlexJWayne

View GitHub Profile
// exported types will be available for you to import from compiled files
// to distinguish between objects ({}) and blocks, blocks have a colon before the opening brace (:{})
export type parseRoute = (route: string) => :{
// assign computations to variables like this
let parts = route.split("/"); // -> ["users", "<id:string>", "posts", "<index:number>"]
// last expression is the return value, like in Rust
parts
// method chaining!
.filter((part) => part.startsWith("<")) // -> ["<id:string>", "<index:number>"]
export * from './types'
import { setHost, setApiKey } from './req'
import * as auth from './api/auth'
import * as blocks from './api/blocks'
import * as costCodes from './api/cost-codes'
import * as equipment from './api/equipment'
import * as reporting from './api/reporting'
import * as sites from './api/sites'
import React, { useState, useEffect } from 'react'
import ItemList from './item-list'
export const CurrentItems = React.createContext([])
const api = {
async getItems() {
return parseItemsOrWhatev(fetch('http://foo.com/items'))
}
}
# same as Ch5_1b (loops with user input list of numbers generating the count, total and average) but with max and min values instead of count aveage and total
# Setting the running smallest and largest numbers to none so they are defined
smallest_number = None
largest_number = None
# User input loop
while True:
string_number = input('Enter a number.')
# Denoting end of loop with 'done' and printing output of smallest and largest numbers from user list
# This program asks for a decimal value and calculates the corresponding
# letter grade.
# Ask the user for the score.
score_as_string = input('Please enter score between 0 and 1: ')
# Convert the string returned by input() to a number.
try:
score = float(score_as_string)
except:
Compiling code for electron
Including:
/Users/alex/Projects/tower/tower.ino
/Users/alex/Projects/tower/FastLED/bitswap.h
/Users/alex/Projects/tower/FastLED/chipsets.h
/Users/alex/Projects/tower/FastLED/color.h
/Users/alex/Projects/tower/FastLED/colorpalettes.h
/Users/alex/Projects/tower/FastLED/colorutils.h
/Users/alex/Projects/tower/FastLED/controller.h
var resize_interval;
// resize AFTER resize finished, and don't do again for a second or so
window.onresize=function(){
// Window was resized, so cancel any previous deferred resize handlers.
clearTimeout(resize_interval);
// Call this every 750ms
resize_interval = setTimeout(function () {
var resize_blocker = Date.now();
var resize_interval;
// resize AFTER resize finished, and don't do again for a second or so
window.onresize=function(){
// window was resized, so cancel any previous deferred resize handlers.
clearTimeout(resize_interval);
// Call this every 250ms
resize_interval = setTimeout(function () {
import UIKit
// test harness
func timeBlock(block: () -> Void) {
let start = clock()
block()
let diff = clock() - start
let msec = diff * 1000 / UInt(CLOCKS_PER_SEC)
print("Time taken: \(msec) milliseconds")
}

if is not an expression, meaning it does not return a value. A ternary is an expression, meaning it does return a value. This allows you to use it on the right hand side of an assignment operator.

So when assigning things, this is needlessly verbose

var someEl = document.getElementById('some-element');
if (isCool) {
  someEl.innerText = 'totally cool';
} else {
  someEl.innerText = 'NOT COOL YO';

}