Skip to content

Instantly share code, notes, and snippets.

@1995eaton
1995eaton / create_bootable_drive.txt
Created Sep 10, 2022
Create a bootable drive from an ISO in Windows
View create_bootable_drive.txt
cmd:
disk part
list disk
select disk X
clean
create partition primary
select partition 1
format fs=ntfs quick
active
exit
View is_prime.js
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`);
View aur.py
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
Reddit Subreddit Completion
View subreddit_complete.py
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'
View to_base.cc
#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
Drive Ya Nuts Solver
View drive_ya_nuts.cc
// 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 Apr 27, 2016
Miller-Rabin primality test using GMP in C99
View prime.c
#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 Dec 6, 2015
Quicksort implementations
View quicksort.cc
#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++)
View pi.cc
#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 Oct 17, 2015
Mersenne Twister (32 and 64 bit) C89+ header
View mt.h
#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); \