Skip to content

Instantly share code, notes, and snippets.

View codyromano's full-sized avatar

Cody Romano codyromano

  • Facebook
View GitHub Profile
@codyromano
codyromano / simpleRuntimeValidation.ts
Created May 12, 2024 00:00
Simple runtime validation for data types in complex web apps (e.g. games)
// Let's say we have coordinates in a game. Managing the location of objects can be tricky,
// and we want to validate that nothing flows off the screen
export type PositionDataType = {
x: number;
y: number;
};
// Here's a utility for creating a position data type with runtime validation
export const positionDataType = createDataType<PositionDataType>('position')
@codyromano
codyromano / untitled.md
Last active January 24, 2021 21:22
Healthy political and religious discussions....on the internet??

Untitled

Untitled is a social experiment that challenges people of different faiths & political backgrounds to explore — and in some cases embrace — each other's beliefs. It will launch as a web-based game in mid-2021.

Motivation

The game aims to tackle two common problems in debates about politics & religion:

  1. Labeling. Labels like "conservative", "liberal", "Christian" or "Muslim" oversimplify people's beliefs. Though labeling is a natural human tendency, participants in a debate must be willing and able to unpack labels to understand what each other actually thinks.
  2. Unconscious bias. Implicit or explicit biases kick in when someone sees a stranger's basic profile: picture, name, job title, hometown. Identity characteristics warp the lens through which we perceive strangers' beliefs.
@codyromano
codyromano / count_filler_words.js
Last active December 15, 2020 16:30
Practice public speaking by counting how many filler words you use during presentations
/*
Using Google Chrome on your desktop (not mobile):
1. Copy all of this
2. Go to a *different* webpage (any webpage)
3. In the top bar, click "View" > "Developer" > "JavaScript Console"
A prompt will appear asking you to choose filler words and how long you want to speak.
*/
(function countHowManyTimesIUsedFillerWordsDuringAMeeting(fillerWords, secondsToRecord) {
import jwksClient from 'jwks-rsa';
import jsonWebToken from 'jsonwebtoken';
const jwksUri = 'https://appleid.apple.com/auth/keys';
const client = jwksClient({
jwksUri
});
function getKey(header, callback) {
client.getSigningKey(header.kid, function(err, key) {
const GET_CONVERSATION = gql`
query GetConversation($request: GetConversationInput!) {
getConversation(request: $request) {
conversation {
id
}
}
}
`;
// Options available when creating the HOC
export type WithFocusQueryOptions<ComponentProps, QueryVars> = {
query: DocumentNode;
getQueryVars?: (props: ComponentProps) => QueryVars;
};
// Props provided to the wrapped component
export type WithFocusQueryProps<QueryResponse, QueryVars> = {
data: QueryResponse;
refetch: (options?: QueryVars) => void;

Living persona project (working title)

Problem

For-profit companies define user archetypes called “personas” before developing a product. A typical persona includes a face, a name and a problem description. “I’m Jamal, a premed student, and I need books for next semester. Can I find them on Amazon.com?”

In combination with quantitative research, personas offer a window into customers’ thoughts and feelings. It’s frighteningly easy to build something useless when you haven’t fleshed out the underlying problem.

Most nonprofits don’t have evidence-based personas for the communities they serve because the research is expensive and time consuming. This creates a chicken-and-egg problem: it costs money to gather stories about people who need your help, yet the narratives are essential to grant writing.

const findWordsInMatrix = (matrix, dictionary) => {
// Convert dictionary to map for O(1) lookup
// We could also use a trie here (more efficient, but verbose implementation)
const dictionary = dictionary.reduce((set, word) => {
set.add(word);
return set;
}, new Set());
const wordsFound = new Set();
const visited = new Map();
/**
* Let's say we want to find the shortest path among *all* pairs
* of U.S. cities. For example, let's assume (for the sake of argument)
* that Seattle is 200 miles from Chicago, 300 miles from Miami, etc.
*/
const cities = [
{
name: 'Seattle',
edges: [
['Chicago', 200],
/*
Initial questions:
- How large is the grid?
- What is the format of the input I'm given?
- Is the player guaranteed to exist on the grid?
- Is there always going to be a blocking tile?
Proposal: dynamic programming
- If adjacent tile is out of bounds (e.g. we're at