Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@marcospgp
marcospgp / Hash.cs
Last active May 10, 2022 21:41
FNV 1a Hash in C# for use with Unity
using System;
using System.Text;
using UnityEngine;
/// <summary>
/// An implementation of the Fowler–Noll–Vo 1a hash
/// https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function#FNV-1a_hash
/// http://www.isthe.com/chongo/tech/comp/fnv/index.html
/// </summary>
namespace MarcosPereira.Terrain {
@marcospgp
marcospgp / SafeTask.cs
Last active October 7, 2024 12:47
Cancel async tasks in Unity upon exiting play mode
using System;
using System.Threading;
using System.Threading.Tasks;
using UnityEngine;
namespace UnityUtilities
{
/// <summary>
/// A replacement for `Task.Run()` that cancels tasks when entering or
/// exiting play mode in the Unity editor (which doesn't happen by default).
@marcospgp
marcospgp / FloatingOrigin.cs
Last active March 14, 2024 06:59
A floating origin script for Unity.
// Based on script found at http://wiki.unity3d.com/index.php/Floating_Origin
// on 2021-05-13, modified substantially - mostly to accomodate multiplayer,
// by introducing threshold and offset values.
using UnityEngine;
public class FloatingOrigin : MonoBehaviour {
public static FloatingOrigin Instance;
// Largest value allowed for the main camera's X or Z coordinate before that
@marcospgp
marcospgp / JellyCube.cs
Created December 4, 2020 23:09
Unity C# script that jellifies a cube.
using System.Linq;
using UnityEngine;
[RequireComponent(typeof(MeshFilter))]
public class Jellify : MonoBehaviour {
[SerializeField]
[Tooltip("The object's resistance to outside forces. Default value is 10.")]
[Range(1f, 1000f)]
private float stiffness = 10f;
@marcospgp
marcospgp / waitbutwhy-procrastination-summary.md
Last active September 16, 2022 17:52
A summary of waitbutwhy's blog posts on beating procrastination.

Why procrastinators procrastinate

Inside our minds there is a rational decision maker, who is a good planner and cares about our future. The rational decision maker knows what needs to be done to maximize happiness in the long term and make us be successful in our dreams and aspirations.

The instant gratification monkey also lives in the mind. It often goes against the rational decision maker, especially in the mind of an avid procrastinator. His favorite activity is to find the easiest, lowest stakes activity it can to help maximize pleasure in the present moment.

Sometimes a third character appears in the mind: the panic monster. Typically accompanied by a looming deadline or the threat of social disgrace, the panic monster drives the procrastinator to jump into action and sprint through the task at hand.

It's not good for a procrastinator to rely on the panic monster:

@marcospgp
marcospgp / ideas-for-startups-dropdown-reading.md
Last active August 19, 2022 01:58
Experimenting with a new way of reading long form text with Paul Graham's Ideas For Startups

Ideas For Startups

Written by Paul Graham and copied from http://www.paulgraham.com/ideas.html

October 2005

(This essay is derived from a talk at the 2005 Startup School.)

People think it's hard to come up with good ideas for startups because they don't actually try to do it.
@marcospgp
marcospgp / .eslintrc.js
Created April 17, 2019 15:27
An example ESLint configuration for typescript to be used with the VSCode ESLint plugin. It's built with airbnb-base, prettier, and most well known ESLint plugins. It took a long time to configure so I thought it should be shared for others to reuse.
module.exports = {
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"extends": [
"eslint:recommended",
"airbnb-base",
"plugin:eslint-comments/recommended",
"plugin:promise/recommended",
@marcospgp
marcospgp / Preferences.sublime-settings.js
Created September 1, 2016 13:51
User preferences for better readability on sublime text 3
{
"atomic_save": true,
"color_scheme": "Packages/Material Theme/schemes/Material-Theme.tmTheme",
"font_size": 10,
"ignored_packages":
[
"Vintage"
],
"spacegray_tabs_xlarge": true,
"theme": "Material-Theme.sublime-theme",
@marcospgp
marcospgp / ScrollingBackground.cs
Last active August 29, 2015 14:21
Unity 2D Horizontal Sprite Scroller
using UnityEngine;
using System.Collections;
public class ScrollingBackground : MonoBehaviour {
// Here's what this script does, step by step:
// Duplicates the object
// Scrolls both at a given scrollSpeed
// When an object's full length has been scrolled, it is placed on the duplicate's original position
// Last step is repeated for both objects indefinitely