Skip to content

Instantly share code, notes, and snippets.

View keyle's full-sized avatar
👹

keyle

👹
View GitHub Profile
@keyle
keyle / FPS mousemove.as
Last active August 29, 2015 14:05
wrong FPS way
// listening to flash stage...
// can't figure out the MouseCollision thing
Main.stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove, false, 0, true);
// ...
private var tally:Number = 0;
private function mousemove(event:MouseEvent):void
@keyle
keyle / FPS mousemove2.as
Last active August 29, 2015 14:05
Fullscreen FPS the right way?
stage.addEventListener(MouseEvent.MOUSE_MOVE, mousemove, false, 0, true);
scene3D.addEventListener(Scene3D.UPDATE_EVENT, update, false, 0, true);
private function mousemove(event:MouseEvent):void
{
if (event.movementX != 0) {
const mouseMoveX:Number = (event.movementX);
spinX += mouseMoveX * 0.035;
}
@keyle
keyle / Flare3DView.as
Created August 31, 2014 04:44
unresponsive mouse after a while
package game
{
import flare.basic.Scene3D;
import flare.basic.Viewer3D;
import flare.core.Camera3D;
import flare.core.Mesh3D;
import flare.core.Pivot3D;
import flare.core.Texture3D;
import flare.flsl.FLSLMaterial;
import flare.physics.colliders.SphereCollider;
import irc, asyncdispatch, strutils, os, threadpool
proc onIrcEvent(client: PAsyncIrc, event: TIrcEvent) {.async.} =
case event.typ
of EvConnected:
discard
of EvDisconnected, EvTimeout:
await client.reconnect()
of EvMsg:
if event.cmd == MPrivMsg:
import macros
macro eval(s: string): expr =
result = parseStmt($s)
eval("echo 5")
@keyle
keyle / pipein.nim
Created January 10, 2015 15:07
Get the content piped into nim process
# option 1
let x = stdin.readAll
echo "^ " & x
# option 2
while not endoffile(stdin):
let x = stdin.readLine
echo "^ " & x
@keyle
keyle / werp.py
Last active August 29, 2015 14:13
toy programming language, lispish and concise.
# werp.py :: toy programming language, lispish and concise.
tokenize = lambda chars: chars.replace('(', ' ( ').replace(')', ' ) ').split()
def read_from_tokens(tokens):
if len(tokens) == 0:
raise SyntaxError('Unexpected EOF')
token = tokens.pop(0)
if token == "(":
L = []
@keyle
keyle / readme.md
Created October 25, 2019 06:10 — forked from xem/readme.md
Maths & trigonometry cheat sheet for 2D & 3D games

Conventions

  • A = [xA, yA] is a point on the 2D plane. Same for B, C, ...
  • lengths are in any unit (ex: pixels)
  • code snippets are in JavaScript

Degrees to radians

angleRad = angleDeg * Math.PI / 180;

@keyle
keyle / docker-always-restart.sh
Created November 3, 2019 22:06
Docker container always start at boot
# docker ps, find the hash, e.g. b1d085e45f39
docker update --restart=always $1
@keyle
keyle / NSImageViewFill.swift
Created May 3, 2020 05:36
NSImageView with Fill Aspect Ratio for Swift 4/5+
//
// NSImageViewFill.swift
// NSImageView with Fill Aspect Ratio
// Swift 4.0+
//
// Written by (source) https://stackoverflow.com/a/46262418/200041
// I take no credit in this but it's too awesome not to gist.
//
import Cocoa