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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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);