Skip to content

Instantly share code, notes, and snippets.

@1995eaton
1995eaton / create_bootable_drive.txt
Created September 10, 2022 18:51
Create a bootable drive from an ISO in Windows
cmd:
disk part
list disk
select disk X
clean
create partition primary
select partition 1
format fs=ntfs quick
active
exit
@1995eaton
1995eaton / is_prime.js
Created July 3, 2016 14:03
Regex prime test
function isPrime(n) {
if (n <= 1)
return false;
var pattern = new RegExp('^(.{2,' + Math.ceil(Math.sqrt(n)) + '})\\1+$');
return !pattern.test('.'.repeat(n));
}
var n = ~~process.argv[2];
console.log(`${n} ${isPrime(n) ? 'is' : 'is not'} prime`);
@1995eaton
1995eaton / aur.py
Created May 26, 2016 10:21
Aur searcher
from datetime import datetime
import shutil
import textwrap
import requests
API_URL = 'https://aur.archlinux.org/rpc/?v=5'
def format_text(text, color=None, bold=False):
@1995eaton
1995eaton / subreddit_complete.py
Created May 26, 2016 10:18
Reddit Subreddit Completion
import sys
import uuid
import re
import json
import urllib.request
import urllib.parse
subreddit_rx = re.compile(r'\A[A-Za-z0-9][A-Za-z0-9_]{,20}\Z')
subreddit_url = 'https://www.reddit.com/api/search_reddit_names.json'
#include <iostream>
template <typename T, typename U = typename std::make_unsigned<T>::type>
std::string to_base(T _n, int base) {
static const char *base_vals = "0123456789"
"abcdefghijklmnopqrstuvwxyz"
"ABCDEFGHIJKLMNOPQRSTUVWXYZ";
static char buf[8 * sizeof (U) + 1];
U n = _n;
@1995eaton
1995eaton / drive_ya_nuts.cc
Last active May 12, 2016 05:06
Drive Ya Nuts Solver
// Solution to Drive Ya Nuts
// http://www.hasbro.com/common/instruct/DriveYaNuts.PDF
//
// Program output:
//
// 1 3 5 4 2 6
// 1 5 3 2 6 4
// 3 4 5 6 1 2
// 5 2 4 6 1 3
// 4 3 2 1 6 5
@1995eaton
1995eaton / prime.c
Created April 27, 2016 13:29
Miller-Rabin primality test using GMP in C99
#include <stdio.h>
#include <gmp.h>
unsigned urandom(void) {
unsigned r;
FILE *fp = fopen("/dev/urandom", "r");
fread((void *)&r, sizeof r, 1, fp);
fclose(fp);
return r;
}
@1995eaton
1995eaton / quicksort.cc
Last active December 6, 2015 01:01
Quicksort implementations
#include <iostream>
#include <random>
#include <vector>
namespace ArrayUtils {
std::vector<uint32_t> random_array(uint32_t low, uint32_t high, size_t count) {
std::vector<uint32_t> result(count);
std::mt19937 eng(std::random_device{}());
std::uniform_int_distribution<uint32_t> gen(low, high);
for (size_t i = 0; i < count; i++)
@1995eaton
1995eaton / pi.cc
Created November 19, 2015 22:04
Pi
#include <iostream>
#include <cmath>
#include <omp.h>
#include <gmp.h>
#define LOG2_10 3.321928094887362
std::string pi(size_t places) {
size_t scaled = ceil(static_cast<double>(places) / 14);
mpf_set_default_prec(LOG2_10 * places);
@1995eaton
1995eaton / mt.h
Created October 17, 2015 23:57
Mersenne Twister (32 and 64 bit) C89+ header
#ifndef MT_H
#define MT_H
#define MT_GEN(TYPE, NAME, W, N, M, A, U, D, S, B, T, C, F, L, LM, UM) \
typedef struct { \
TYPE MT[N]; \
TYPE index; \
} NAME; \
void NAME##_seed(NAME *mt, TYPE seed) { \
mt->index = (N); \