Skip to content

Instantly share code, notes, and snippets.

@lexbailey
lexbailey / FlameSpiral.cpp
Created March 19, 2014 18:27
This is a c++ program that looks like a flame! what could be cooler than that?
#include <stdio.h>
#include <stdlib.h>
#define xD int
#define CB p[x]
#define l8(o) for(int o =0; o <n; o ++){
#define D(C) if(C+1!=n)
#define O8 printf(
//The flame of spiraling numbers
//run this program and enter a positive integer to get a number spiral with the specified width
glBegin(GL_QUADS);
glColor3f(1.0f, 0.0f, 0.0f);
glVertex3f(1,1,1);
glVertex3f(-1,1,1);
glVertex3f(-1,-1,1);
glVertex3f(1,-1,1);
glColor3f(1.0f, 1.0f, 0.0f);
glVertex3f(1,1,1);
glVertex3f(-1,1,1);
@lexbailey
lexbailey / squash.sh
Last active August 29, 2015 14:06
This script will squash all changes after the first commit in a git repo into one large blob. This leaves your initial commit and one commit with message "Trololololol"
#!/usr/bin/env sh
echo '#!/usr/bin/env perl
$n=$ARGV[0];my$i;
open($i,'"'"'<'"'"',$n)or die$!;@p=<$i>;
open($i,'"'"'>'"'"',$n)or die$!;
for(@p){$a&&$_=~s/pick/s/;$a=1;
printf$i $_}' > s.pl
echo '#!/usr/bin/env perl
$n=$ARGV[0];my$i;
open($i,'"'"'>'"'"',$n)or die$!;
@lexbailey
lexbailey / BBBLoginTime.sh
Last active August 29, 2015 14:19
The Beaglebone Black has no RTC built in. Add this code to the end of your /etc/profile and you will be asked to set the time when you log in.
while true; do
echo -e "\n\nCurrent system time:"
date
read -p "Is this correct? [y/n] " yn
case $yn in
[Yy]* ) break;;
[Nn]* )
read -p "Please enter the current date as DD/MM/YYYY: " userdateinput
echo $userdateinput | perl -pe 's:(\d{2}/)(\d{2}/)(\d{4}):$2$1$3:' | xargs date +"%d/%m/%Y" -s
read -p "Please enter the current time as 24 hour time (HH:MM): " usertimeinput
@lexbailey
lexbailey / pre-commit
Created July 17, 2015 15:20
Git commit hook that checks to see if you added debug prints and then warns you about them and asks if you want to abort.
#!/usr/bin/env bash
# scan the staged files for added prints
git diff --cached | grep -e"+.*print.*" > .diff_contains_prints
# find the number of print lines
NUMPRINTS=`wc -l .diff_contains_prints | sed "s/\(.\).*/\1/"`
# check if there are one or more new print lines
if [[ $NUMPRINTS -ge 1 ]]
#!/usr/bin/bash
# Script to confirm git commits with -a if files are already staged.
# Alias git to this script in your shell.
# If no options are given, call git with no options (and optionally accuse the user of being a fool)
if [[ $# < 1 ]]
then
git
exit
@lexbailey
lexbailey / g2you_login.js
Last active March 29, 2017 10:14
A proof of concept JS exploit to log in to a glasses2you.co.uk account without a password (They've patched the problem now)
/*
Before this problem was patched, you could go to http://www.glasses2you.co.uk/ and click
on "YOUR ACCOUNT", type in the email address of the target account and click next, then
just paste this file into the javascript console (after making the obvious change that
makes it work for any account).
After that, you'd wait for about thirty seconds and the password would be printed on the
console, then you could click some other link on the site and you'd be logged in on the
next page.
@lexbailey
lexbailey / timetravel.py
Last active May 4, 2017 17:44
When your unit tests call time.sleep quite frequently, they can run quite slowly. This function fixes that.
"""
Make tests go faster.
usage:
import timetravel
timetravel.enable_time_travel()
"""
import sys
import datetime
import time
class Vector():
""" Horrible bad vector implementation """
def __init__(self, *args):
self._vector = list(args)
def __str__(self):
return str("<%s>" % (", ".join([str(v) for v in self._vector])))
def __getitem__(self, index):
return self._vector[index]