Skip to content

Instantly share code, notes, and snippets.

Avatar

Ian Sutherland iansu

View GitHub Profile
@iansu
iansu / dataloader.js
Last active Dec 8, 2021
Minimal Dataloader implementation
View dataloader.js
/*
* This is a minimal implementation of Dataloader. This implementation leaves out the caching functionality
* and skips most of the error handling so it's not suitable to use in production. This is meant to help
* you understand how Dataloader works. Once you understand this code check out the full Dataloader code:
* https://github.com/graphql/dataloader
*/
class Dataloader {
constructor(batchFunction) {
this.batchFunction = batchFunction;
@iansu
iansu / resources.md
Last active Oct 14, 2021
The Past, Present, and Future of JavaScript
@iansu
iansu / npm.js
Created May 18, 2021
A ScriptKit script to search npm
View npm.js
// Menu: npm
// Description: Search npm
// Author: Ian Sutherland
// Twitter: @iansu
await arg("Search query:", async () => {
let query = await arg("Search query:")
exec(`open https://www.npmjs.com/search?q=${query}`)
})
View machine.js
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@iansu
iansu / README.md
Last active Jun 20, 2022
Display shell architecture in prompt
View README.md

Display the architecture (arm64 or x86) of the current shell in your prompt using Starship. I use zsh as my shell but you should be able to adapt this for other shells. As a bonus this also shows you how to set up your path to work with both arm64 and x86 versions of Homebrew.

Add this to your ~/.zshrc:

if [[ $(arch) == 'arm64' ]]; then
  export PATH="$HOME/bin:/opt/homebrew/bin:/opt/homebrew/sbin:$PATH"
  export SHELL_ARCH="arm64"
  echo '=========== arm64 ============'
else
@iansu
iansu / butter.ts
Created Feb 12, 2021
Butter CMS Integration
View butter.ts
import Butter from 'buttercms';
const butter = Butter('api_key');
const getHomePage = async () => {
const homePage = await butter.page.retrieve('*', 'sample-page');
return homePage.data.data;
};
@iansu
iansu / README.md
Last active Apr 5, 2022
Using React 17 and the new JSX transform with Create React App 4.0 Alpha
View README.md

Using React 17 and the new JSX transform with Create React App 4.0 Alpha

Create React App 4.0 is currently in alpha and supports using React 17 and the new JSX transform. To use it, follow these instructions.

Create a new app

Create a new app with npx create-react-app@next --scripts-version=@next --template=cra-template@next my-js-app

Update to React 17

@iansu
iansu / README.md
Last active Mar 1, 2021
Create React App 4.0 Alpha Testing
View README.md

Create New App

JavaScript Template

npx create-react-app@next --scripts-version=@next --template=cra-template@next my-js-app

TypeScript Template

npx create-react-app@next --scripts-version=@next --template=typescript@next my-ts-app

@iansu
iansu / .bash_profile
Created Apr 20, 2019
Automatically run nvm when entering a directory with a .nvmrc file
View .bash_profile
_enter_dir() {
local git_root
git_root=$(git rev-parse --show-toplevel 2>/dev/null)
if [[ "$git_root" == "$PREV_PWD" ]]; then
return
elif [[ -n "$git_root" && -f "$git_root/.nvmrc" ]]; then
nvm use
NVM_DIRTY=1
elif [[ "$NVM_DIRTY" == 1 ]]; then
@iansu
iansu / fizzbuzz.rb
Last active Jun 7, 2016
FizzBuzz in Ruby
View fizzbuzz.rb
for i in 1..100
print "#{i} "
print "fizz" if i % 3 == 0
print "buzz" if i % 5 == 0
print "\n"
end