Skip to content

Instantly share code, notes, and snippets.

View DomNomNom's full-sized avatar

DomNomNom DomNomNom

View GitHub Profile
@DomNomNom
DomNomNom / asciiClock.py
Created May 28, 2016 16:56
Prints the current time in nice ascii art. Clean code using numpy
import numpy as np
charWidth = 3
char2index = { c : i*charWidth for i,c in enumerate('0123456789: ')}
bigAlphabet = '''
_ _ _ _ _ _ _ _ |
| | | _| _||_||_ |_ ||_||_| . |
|_| ||_ _| | _||_| ||_| | . |
'''[1:-1].split('\n')
bigAlphabet = np.array(list(map(list, bigAlphabet)))
@DomNomNom
DomNomNom / ZigZag.js
Last active July 9, 2017 03:02
Count the number of zig zags in an array (switches from increasing to decreasing or from decreasing to increasing)
// Counts how often a sequence zig zags.
// ie. switches from increasing to decreasing or from decreasing to increasing
// countZigZags([]) --> 0
// countZigZags([5,5,5,5]) --> 0
// countZigZags([1,2,3]) --> 0
// countZigZags([1,2,3,2,1]) --> 1
// countZigZags([5,6,5,6,5]) --> 3
// countZigZags([2,2,2,6,6,5,5]) --> 1
function countZigZags(numbers) {
@DomNomNom
DomNomNom / twice_as_shifty.py
Created July 25, 2017 11:48
Twice as shifty
# Find a number n which is_twice_as_shifty(n)
def is_twice_as_shifty(n):
n = int(n)
if n < 1:
return False
n_str = str(n)
n_times_two_str = n_str[-1] + n_str[:-1] # Shift the digits around
n_times_two = int(n_times_two_str)
@DomNomNom
DomNomNom / RpcClient.js
Created September 14, 2017 11:12
Hiding a private key by using JS scopes and closures
const rp = require('request-promise-native');
const crypto = require('crypto');
const assert = require('assert');
const signatureMethod = 'RSA-SHA256'
const protocolVersion = '0.0.1';
const signatureEncoding = 'base64';
class RpcClient {
@DomNomNom
DomNomNom / physics.md
Last active November 14, 2017 11:25
What would happen to the moon the density of earth was suddenly halved?

radius r =
       384000 km
       384000000 m

period p =
       27.3 days
       2358720 s

moon's speed =
       d / t

@DomNomNom
DomNomNom / controller_input.py
Last active February 7, 2018 00:57
Controller input for RLBot
from inputs import get_gamepad # pip install inputs
import threading
def deadzone(normalized_axis):
if abs(normalized_axis) < 0.1: return 0.0
return normalized_axis
class ControllerInput:
def __init__(self):
# self.fThrottle = 0.0
@DomNomNom
DomNomNom / Murphy42.cpp
Last active August 7, 2018 01:24
Accidentally breaks C++ Access Rights while computing The Answer to the Ultimate Question of Life, the Universe, and Everything.
#include <iostream>
// File x.h
// This class was named X to be consistent with http://www.gotw.ca/gotw/076.htm
//
// Its primary purpose is to hold a private value which no one should be able
// to accidentally modify.
class X
{
public:
@DomNomNom
DomNomNom / Murphy42_OO.cpp
Last active August 8, 2018 04:15
Accidentally breaks C++ Access Rights while computing The Answer to the Ultimate Question of Life, the Universe, and Everything. This one is coded in a more Object Oriented fashion
#include <iostream>
// This class was named X to be consistent with http://www.gotw.ca/gotw/076.htm
//
// Its primary purpose is to hold a private value which no one should be able
// to accidentally modify.
class X {
public:
X() : private_(1) { /*...*/ }
int getValue() { return private_; }

In some future time, once bars may open again, Alice and her partner Bob head over to indulge in this way of socializing again. There are four other couples in the bar which, eager for social contact, do these cute footshakes with each person they haven't met before. After this initial mingling, Alice asks everyone how many people they did footshakes with. As some people knew each other beforehand, she gets nine different answers back.

How many footshakes did Bob do?

@DomNomNom
DomNomNom / coins_cover_points.md
Last active May 22, 2020 03:56
A deceptively hard circle covering puzzle

You play a game against Malory, in which you choose points on the 2D plane and Malory wins if she can cover them by using non-overlapping pennies (disks of radius 1). Show a minimal set of points that guarantees you a win.

Hint

At low numbers of dots, Malory is favoured (if there is 1 dot, just cover it with 1 circle), and at high numbers of dots you are favoured (e.g. by using a grid approach like https://www.desmos.com/calculator/gwwcn40xcp)

Here's something that'll let you test out your theories: https://www.desmos.com/calculator/ifhtfwhnqm