Skip to content

Instantly share code, notes, and snippets.

View oliverbooth's full-sized avatar
🔷
Reticulating splines

Oliver Booth oliverbooth

🔷
Reticulating splines
View GitHub Profile
@oliverbooth
oliverbooth / decimal-conjecture
Created December 10, 2016 20:42
This seems to work...
/*
* return the number of zeros immediately proceeding the decimal point for any
* (-1 < n < 1)
*/
floor(abs(log10(abs(n))))
@oliverbooth
oliverbooth / win-google-feud.js
Last active August 29, 2015 14:17
Instantly Win Google Feud
/* Run this in the Console of the developer tools in whatever browser you are using.
* (Usually, you can just hit F12 to open it)
*/
var r=window.gameData.googleResults;for(var i=0;i<r.length;i++){$("#rebox").val(r[i]);$("#guess").click()}
@oliverbooth
oliverbooth / RepeatGround.cs
Created March 10, 2015 11:28
Hack for "repeating" ground
using UnityEngine;
using System.Collections;
public class RepeatGround : MonoBehaviour
{
public GameObject surfacePrefab;
public GameObject soilPrefab;
public Vector2 widthRange = new Vector2(-100, 100);
public int numLayers = 10;
@oliverbooth
oliverbooth / gist:0426cd20cb95661e709b
Created November 15, 2014 23:19
Useful calculation to turn INDEX into X/Y-coordinates and vice-versa
i = x + (y * w)
x = i % w
y = i / w
@oliverbooth
oliverbooth / Portal 2 TAB-toggle
Created November 7, 2014 17:10
Changes TAB to toggle co-op player's view instead of hold-to-use.
alias screen_open "+remote_view; bind TAB screen_close"; alias screen_close "-remote_view; bind TAB screen_open"; bind TAB "screen_open"
@oliverbooth
oliverbooth / swap.c
Created October 19, 2014 14:50
Integer swap in C
#define SWAP(x,y) do{ x^=y; y^=x; x^=y; } while (0);
@oliverbooth
oliverbooth / randomFile.php
Last active August 29, 2015 14:06
Randomly choose a file
<?php
/**
* Randomly chooses a file from the given directory.
* @param directory Optional. The directory to search. Defaults to the current directory.
* @param ext Optional. An array of accepted file extensions to match. Defaults to standard images.
* @return A string representing the name of the file
*/
function randomFile($directory = ".", $ext = array("jpg", "jpeg", "gif", "png", "bmp")) {
// Find file matches using glob
$files = glob($directory."/*.{".implode(",",$ext)."}", GLOB_BRACE);
@oliverbooth
oliverbooth / math.c
Created July 9, 2014 21:39
Even checker
bool is_even(int i) {
char buf[10]; // Probably big enough
float f = (float)i;
f /= 2;
sprintf(buf, "%lf", f);
for (int ii = 0; ii < 10 - 1; ++ii) {
if (buf[ii] == '.' && buf[ii+1] == '5') {
return true;
}
}
@oliverbooth
oliverbooth / FloatObject.cs
Last active October 9, 2021 21:58
Floating-like objects in Unity
using UnityEngine;
/// <summary>
/// Represents a behavior script which will cause the object to float following a sine wave pattern.
/// </summary>
public class FloatObject : MonoBehaviour
{
[SerializeField] private float _amplitude = 0.25f;
[SerializeField] private float _frequency = 1f;
private float _t = 0f;
@oliverbooth
oliverbooth / happy-birthday.c
Last active August 29, 2015 13:56
Happy Birthday!
#include <stdio.h>
int main(int argc, char *argv[]) {
if(argc == 1)
printf("Whose birthday is it?\n");
else if (argc == 2)
for(int i = 1; i <= 4; i++)
printf("Happy birthday %s %s\n", i % 3 == 0 ? "dear" : "to", i % 3 == 0 ? argv[1] : "you");
else
printf("Too many.\n");