Skip to content

Instantly share code, notes, and snippets.

View sophec's full-sized avatar
🖤
[[maybe_unused]]

Sophie Eccles sophec

🖤
[[maybe_unused]]
View GitHub Profile
@sophec
sophec / Fitts Test Hack.js
Created November 6, 2018 18:56
A quick hack for http://fww.few.vu.nl/hci/interactive/fitts/ that lets you get any time you want.
// use with this site http://fww.few.vu.nl/hci/interactive/fitts/
var cheat = (atime) => {
var doc = document.getElementsByTagName("iframe")[0].contentDocument.getElementsByTagName("iframe")[0].contentWindow;
var nextbutton = document.getElementsByTagName("iframe")[0].contentDocument.getElementById("clicknext");
var avgtime = 0; // what the average time should be in ms
if (atime && atime > 0)
avgtime = atime;
if (atime && atime < 10 && atime > 0) {
@sophec
sophec / doubles.cpp
Last active October 16, 2018 14:53
A simple program to print out the base 2 (binary) representation of a 64-bit double (including sample output).
#include <iostream>
#include <cmath>
/* Double Basics:
* The basic format of a IEEE 754 64-bit double is the following:
* 1 00000000000 0000000000000000000000000000000000000000000000000000
* b63 is the sign bit, 1 = negative, 0 = positive
* b52-b62 are the 11 exponent bits
* b0-b51 are the 52 fraction/significand bits
*
@sophec
sophec / coinflip.cpp
Created November 14, 2017 03:45
WAY overcomplicated coinflip program which I used to decide which new phone to buy.
#include <iostream>
#include <ctime>
#include <random>
#include <ctime>
#include <string>
#include <cstdio>
enum coinFace {
HEADS = 0,
TAILS = 1
@sophec
sophec / english wordlist.txt
Created September 27, 2017 18:32
a list of english words, can be used for spellcheck or whatever you want :)
This file has been truncated, but you can view the full file.
aa
aah
aahed
aahing
aahs
aal
aalii
aaliis
aals
aardvark
@sophec
sophec / newstack.h
Last active May 9, 2017 16:33
Node-based stack in C++ using C-style pointers vs. C++11 smart pointers.
/**
* This is the right way to do this in C++11+, which is a lot of +'s.
* This uses the std::shared_ptr type to manage memory and access to it magically.
*/
#ifndef STACK_H
#define STACK_H
#include <iostream>
#include <vector>
@sophec
sophec / stack.h
Last active April 11, 2017 17:29
Basic link-based stack implementation in C++.
#ifndef STACK_H
#define STACK_H
#include <iostream>
template <class T>
class stack {
private:
// the node class to be used in the stack
template <class nT = T>
@sophec
sophec / gitrepo
Last active January 27, 2017 16:11
A bash script to easily open a repo on GitHub.com
#! /bin/bash
# likely only works on OS X, but hey, that's just too bad :)
# default username if one is not given
username="willeccles"
if (( $# >= 2 )); then
open "https://www.github.com/$1/$2"
elif (( $# == 1 )); then
@sophec
sophec / javacr
Last active February 7, 2017 16:13
Compile and run a java program in one command.
#! /bin/bash
echo Compiling $1...
# make the build directory if it doesn't exist already
mkdir -p "`pwd`/build"
javac "$1" -d "`pwd`/build"
rc=$? # return code of javac
[ $rc -eq 0 ] || exit $rc; # exit if the return code of the compilation isn't 0
@sophec
sophec / bin.c
Last active December 27, 2016 04:46
Add and subtract numbers using bitwise operators :D
// add a and b
int binadd(int a, int b) {
int carry = (a & b) << 1;
int result = a ^ b;
if (carry == 0)
return result;
else
result = binadd(result, carry);
return result;
@sophec
sophec / README.md
Last active October 27, 2016 02:36
how to thread

Threading

So, you want to learn about std::thread added in C++11? This will include that and a small bit on lambdas, which were also added.

How to make two things happen at once:

note: all code samples assume that <thread>, <iostream>, and (later) <future> have been included.

// both threads will run this
void printThreadNum(int num) {