Skip to content

Instantly share code, notes, and snippets.

View cglosser's full-sized avatar
⚗️

C. Glosser cglosser

⚗️
View GitHub Profile
@cglosser
cglosser / stringFilter.py
Last active July 30, 2018 12:42
Program to randomly filter a character out of a supplied string
import string
import random
def main():
alphabet = list(string.ascii_lowercase)
random.shuffle(alphabet)
alphabet = ''.join(alphabet)
for char in alphabet:
print(char)
@cglosser
cglosser / ranges.cpp
Last active February 8, 2018 15:41
Stateful, python-like ranges and enumerations for C++ iterables
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
template <class T>
class Range {
public:
Range(const T upper) : Range(0, upper, 1) {}
Range(const T lower, const T upper) : Range(lower, upper, 1) {}
@cglosser
cglosser / CAG_clion.xml
Created June 23, 2017 16:33
CLion settings
<code_scheme name="Default">
<option name="RIGHT_MARGIN" value="80" />
<Objective-C>
<option name="INDENT_NAMESPACE_MEMBERS" value="2" />
<option name="INDENT_C_STRUCT_MEMBERS" value="2" />
<option name="INDENT_CLASS_MEMBERS" value="2" />
<option name="INDENT_VISIBILITY_KEYWORDS" value="1" />
<option name="INDENT_INSIDE_CODE_BLOCK" value="2" />
<option name="FUNCTION_BRACE_PLACEMENT" value="2" />
</Objective-C>
@cglosser
cglosser / arraybounds.f90
Created April 25, 2017 14:05
Demonstration of the "invalid" way to pass array bounds in Fortran
program test
implicit none
integer :: a(10)
a = [1,2,3,4,5,6,7,8,9,10]
call print_int_array(a)
end program test
@cglosser
cglosser / lunar_lockout.py
Last active April 9, 2017 23:10
*Basic* rule implementation of the Lunar Lockout puzzle game
import numpy as np
class Robot(object):
def __init__(self, pos, icon):
self.pos = pos
self.icon = icon
def move(self, dx):
self.pos += dx
@cglosser
cglosser / safety.f90
Last active December 20, 2016 20:55
Typesafe aliases of primitives with zero runtime overhead
module indices
type :: localIdx
integer :: val
end type localIdx
type :: globalIdx
integer :: val
end type globalIdx
contains
(*Grab the image off the web*)
img = Import["http://i.imgur.com/XgrV1va.jpg"];
(*Cut it down to just the maze*)
croppedImg = ImageTrim[
img,
{
{3097.716894977169`, 288.36529680365334`},
{3033.4246575342463`, 1346.2648401826486`},
{432.5114155251141`, 1355.0319634703199`},
@cglosser
cglosser / fpc.cpp
Last active March 17, 2016 14:34
Floating point c (mks)
#include <iostream>
#include <iomanip>
#include <limits>
using namespace std;
#define PREC std::setprecision(std::numeric_limits<long double>::digits10 + 1)
int main() {
float c_float;
@cglosser
cglosser / hdd_fanctl.sh
Created February 5, 2016 15:30
Replacing the HDD in a recent-ish iMac without an apple-branded disk causes the system to floor the fan RPMs making for a TON of noise. This script manually overrides the HDD fan speed every ten seconds to quiet things down.
#!/bin/bash
#smartfancontrol.sh
#### enter your preferred values here ##################
speed_min=2000 #RPM
speed_max=5500 #RPM
temp_min=46 #degrees celsius
temp_max=60 #degrees celsius
program test
use ISO_FORTRAN_ENV
implicit none
real(kind=real64) :: x
call random_number(x) ! make sure x has been filled with "random" bits
write(*,*) x