Skip to content

Instantly share code, notes, and snippets.

View tyler-boyd's full-sized avatar

Tyler Boyd tyler-boyd

  • TradeRev
  • Toronto, ON
View GitHub Profile
@tyler-boyd
tyler-boyd / stores.ts
Created February 15, 2022 21:52
Svelte stores in Stencil
import { createStore } from '@stencil/store';
export type Dispatch<T> = (value: T) => void;
export type Updater<T> = (value: T) => T;
export type Mutater<T> = (value: T) => void;
export interface Readable<T> {
subscribe: (subscription: Dispatch<T>) => void;
get: T; // fancy observer shit
}
#!/usr/bin/env node
const process = require("process");
const fetch = require("node-fetch");
if (process.argv.length < 3 || process.argv.length > 4) {
console.error(`Usage: ${process.argv[0]} endpoint timeout`);
process.exit(2);
}
const endpoint = process.argv[2];
@tyler-boyd
tyler-boyd / readme.md
Last active September 3, 2017 21:23
AJAX Form Submission

AJAX Form Submission

Disclaimer

You could do this with a 1-liner, but I'm going to try to explain the different parts (especially AJAX/callbacks) because they're complicated and interesting.

Hooking into the form's submit event

This is similar to other event handlers you've probably seen:

@tyler-boyd
tyler-boyd / readme.md
Last active August 24, 2017 04:12
Using Google Scripts to implement a "Contact" form

Google Apps Script Intro

Check out Google Apps Script. Click "Start scripting", and it should bring you to a google-docs-esque text editor.

Intro to implementing a "web app" script

Documentation

The gist of it is: You implement either a function doGet(e) or a function doPost(e). This function will be run when an HTTP request hits the google script's URL.

@tyler-boyd
tyler-boyd / deploy.rb
Last active May 23, 2018 08:11 — forked from twetzel/deploy.rb
Compile assets locally with Capistrano 3.8.1 and Rails 5.1.1
# Clear existing task so we can replace it rather than "add" to it.
Rake::Task["deploy:compile_assets"].clear
namespace :deploy do
desc 'Compile assets'
task :compile_assets => [:set_rails_env] do
# invoke 'deploy:assets:precompile'
invoke 'deploy:assets:precompile_local'
invoke 'deploy:assets:backup_manifest'
private HashMap<String, String> parseObject(String jsonObject) {
HashMap<String, String> ret = new HashMap<String, String>();
int arrayDepth = 0, objDepth = 0;
boolean inQuotes = false;
String currentKey = "";
String currentElement = "";
for (int i = 0; i < jsonObject.length(); i++) {
char ci = jsonObject.charAt(i);
states = ['start']
transitions = []
final_states = []
simple_symbols = '()[]{}!=<>+-*/%;&,'.split('')
special_symbols = [">=", "<=", "==", "!="]
alpha = ('A'.ord .. 'Z'.ord).map(&:chr) + ('a'.ord .. 'z'.ord).map(&:chr)
numeric = (1..9).map(&:to_s)
alphabet = alpha + numeric + simple_symbols + ['0']
stupid_symbols = ['!']
require 'json'
first = JSON.parse File.read 'first.json'
second = JSON.parse File.read 'second.json'
third = JSON.parse File.read 'third.json'
categories = []
first['filterElementCommands'].each_with_index do |top_level_category_info, index|
top_category = { info: top_level_category_info }
@tyler-boyd
tyler-boyd / quickfactor.cpp
Last active June 9, 2016 13:17
Quickfactor.cpp
#include <vector>
#include <iostream>
using namespace std;
vector<int> factorize(int num){
int smallest_pairing = num;
vector<int> factors;
for(int i=1; i<smallest_pairing; i++)
{