Skip to content

Instantly share code, notes, and snippets.

View a-type's full-sized avatar

Grant Forrest a-type

View GitHub Profile
@a-type
a-type / gist:b26e8fc02e64da9e9709
Created February 24, 2015 20:06
Unity3D 3D Bezier Curve Mesh Generator
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Bezier3D : MonoBehaviour
{
public Vector3 start = new Vector3(0, 0, 0);
public Vector3 end = new Vector3(1, 1, 0);
public Vector3 handle1 = new Vector3(0, 1, 0);
public Vector3 handle2 = new Vector3(1, 0, 0);
@a-type
a-type / recover-ar1100.py
Last active May 20, 2016 16:31
Recover AR1100 Resistive Touchscreen Controller
#!/usr/bin/python
import usb.core
import usb.util
# TURN_INTO = "GENERIC"
TURN_INTO = "MOUSE"
USB_MODE_GENERIC = [0x55, 0x01, 0x70]
USB_MODE_MOUSE = [0x55, 0x01, 0x71]
@a-type
a-type / immutable.ex
Last active March 22, 2017 18:56
Example Code for Presentation
user = Repo.get(User, id)
updated_user =
user
|> &increment_login_attempts
|> &Repo.update
IO.inspect user # login_attempts = 0
IO.inspect updated_user # login_attempts = 1
@a-type
a-type / SearchBar.js
Created March 12, 2018 14:35
Render Props Form State Provider
// @flow
import StateProvider from './SearchStateProvider';
import Container from './Container';
const renderSearchControls = ({ term, isFocused, onChange, onFocus, onBlur }) => (
<Container isSearchFocused={isFocused}>
<input value={term} onChange={onChange} onFocus={onFocus} onBlur={onBlur} />
</Container>
);
@a-type
a-type / README.md
Last active July 23, 2019 14:52
ArangoDB Relay Cursor Query

Relay Cursor Connection Spec

This is a bit of a hack, because it's hard to calculate hasNextPage in pure AQL. Instead, I'm adding 1 to the number of results, then slicing the result set back down before returning it. If the result set is equal to first + 1, we have a next page.

This query can be run on the example "Social" graph. Try adjusting the first value to 1 to see pagination. Set after to the cursor of the previous result to go to the next page.

@a-type
a-type / typescriptreact.code-snippets
Last active January 17, 2020 20:09
React TypeScript Snippets
{
"TS React FC": {
"scope": "typescriptreact",
"prefix": "rfc",
"body": [
"import React, { FC } from 'react';",
"",
"export interface ${1:${TM_FILENAME/(.*)\\..+$/$1/}}Props {",
" $2",
"}",
@a-type
a-type / machine.js
Last active June 26, 2020 03:15
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@a-type
a-type / meshCollision.ts
Created September 21, 2020 19:08
ThreeJS mesh geometry collider in cannon.js
// supposing "geometry" is a ThreeJS BufferGeometry - if it's a geometry, just skip this step
const geo = new Geometry().fromBufferGeometry(geometry);
const vertices = [];
const indices = [];
// "scale" is a uniform scale you may or may not have applied to your mesh as a whole.
// just set it to 1 if you don't scale the mesh.
for (const vert of geo.vertices) {
vertices.push(vert.x * scale);
@a-type
a-type / hooks.ts
Last active January 9, 2021 23:22
use-javelin
import { ComponentOf, ComponentType, query, Selector } from '@javelin/ecs';
import { useEffect, useRef, useState } from 'react';
import { useWorld } from './useWorld';
function compareIdLists(a: number[], b: number[]) {
return a.sort().join('') === b.sort().join('');
}
export function useEntities(...filters: Selector) {
const [entities, setEntities] = useState<number[]>([]);
@a-type
a-type / sleep.log
Last active April 6, 2021 14:22
Twilio sleep bug log
Some messages have been moved to the Issues panel.
index.js:31900 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
173 @ index.js:31900
o @ index.js:1
(anonymous) @ index.js:1
171../browser @ index.js:31410
o @ index.js:1
r @ index.js:1
(anonymous) @ index.js:1
index.js:26667 2021-04-06T14:07:37.885Z info [connect #1] Connecting to a Room