Skip to content

Instantly share code, notes, and snippets.

View shana's full-sized avatar
🥽
glub glub

Andreia Gaita shana

🥽
glub glub
View GitHub Profile
@shana
shana / FlyCamera.cs
Created February 27, 2020 14:14 — forked from FreyaHolmer/FlyCamera.cs
A camera controller for easily flying around a scene in Unity smoothly. WASD for lateral movement, Space & Ctrl for vertical movement, Shift to move faster. Add this script to an existing camera, or an empty game object, hit play, and you're ready to go~
using UnityEngine;
[RequireComponent(typeof(Camera))]
public class FlyCamera : MonoBehaviour {
public float acceleration = 50; // how fast you accelerate
public float accSprintMultiplier = 4; // how much faster you go when "sprinting"
public float lookSensitivity = 1; // mouse look sensitivity
public float dampingCoefficient = 5; // how quickly you break to a halt after you stop your input
public bool focusOnEnable = true; // whether or not to focus and lock cursor immediately on enable
@shana
shana / goto.cpp
Created November 14, 2018 09:58
Goto in ternary expressions
#include <stdlib.h>
int foo(bool x) {
return x ? ({ b: goto a; 1; }) : ({ a: goto b; 2; });
}
@shana
shana / duff.cpp
Created November 14, 2018 09:54
Duff's device
// Type your code here, or load an example.
void copy(short* to, short* from, int count) {
auto n = (count + 7) / 8;
switch (count % 8) {
case 0: do { *to++ = *from++;
case 7: *to++ = *from++;
case 6: *to++ = *from++;
case 5: *to++ = *from++;
case 4: *to++ = *from++;
case 3: *to++ = *from++;
Rect lastRect = GUILayoutUtility.GetLastRect();
if (Event.current.type == EventType.Repaint)
{
if (game == null)
{
game = new Game();
game.Restart(lastRect);
}
game.Update();
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace GitHub.Unity {
public class Game
{
private Texture2D texture1 = Utility.GetTextureFromColor(Color.blue);
private Texture2D paddleTexture;
private float wallThickness = 2f;
@shana
shana / await.ts
Created July 24, 2018 14:15
await promise without try/catch
const [data, err] = await new Promise((resolve, reject) =>
doSomething(resolve, reject)
)
.then(data => [data, undefined])
.catch(e => [undefined, e]);
@shana
shana / FirstRun.cs
Created April 2, 2018 13:09
FirstRun example
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
[Location("our_cache.txt", LocationAttribute.Location.LibraryFolder)]
public class FirstRun : ScriptObjectSingleton<FirstRun>
{
@shana
shana / ScriptObjectSingleton.cs
Created April 2, 2018 13:07
ScriptObjectSingleton
/*
* MIT License
Copyright (c) 2016-2018 GitHub
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
2018-02-14T20:34:38.931150+00:00 app[web.1]: }
2018-02-14T20:34:38.931232+00:00 app[web.1]: 2018/02/14 20:34:38 "POST /move HTTP/1.1 200 0" 0.000878
2018-02-14T20:34:38.931151+00:00 app[web.1]: }
2018-02-14T20:35:04.717266+00:00 heroku[router]: at=info method=GET path="/" host=test-snake-1234.herokuapp.com request_id=d0304742-a70f-4323-9859-2a4f02d3fbfc fwd="193.106.166.58" dyno=web.1 connect=1ms service=2ms status=200 bytes=226 protocol=http
2018-02-14T20:35:04.716332+00:00 app[web.1]: 2018/02/14 20:35:04 "GET / HTTP/1.1 200 0" 0.000191
2018-02-14T20:35:05.055547+00:00 app[web.1]: 2018/02/14 20:35:05 "GET /favicon.ico HTTP/1.1 404 0" 0.000053
2018-02-14T20:35:05.056303+00:00 heroku[router]: at=info method=GET path="/favicon.ico" host=test-snake-1234.herokuapp.com request_id=ddfc568f-37ed-46bc-88c4-66353faeaaa2 fwd="193.106.166.58" dyno=web.1 connect=1ms service=1ms status=404 bytes=195 protocol=http
2018-02-14T20:35:34.989408+00:00 heroku[router]: at=info method=GET path="/" host=test-snake-1234.herokuapp.
2018-02-14T19:19:21.776159+00:00 app[web.1]: 2018/02/14 19:19:21 routes.go:30: MOVE REQUEST
2018-02-14T19:19:21.777625+00:00 app[web.1]: 2018/02/14 19:19:21 routes.go:35: Bad move request: json: cannot unmarshal string into Go struct field MoveRequest.id of type int
2018-02-14T19:19:21.777684+00:00 app[web.1]: 2018/02/14 19:19:21 helpers.go:20: {
2018-02-14T19:19:21.777686+00:00 app[web.1]: "food": [],
2018-02-14T19:19:21.777687+00:00 app[web.1]: "height": 2,
2018-02-14T19:19:21.777688+00:00 app[web.1]: "id": 0,
2018-02-14T19:19:21.777690+00:00 app[web.1]: "snakes": [
2018-02-14T19:19:21.777691+00:00 app[web.1]: {
2018-02-14T19:19:21.777692+00:00 app[web.1]: "body": [
2018-02-14T19:19:21.777693+00:00 app[web.1]: {