Skip to content

Instantly share code, notes, and snippets.

View prmichaelsen's full-sized avatar
🌚

Patrick Michaelsen prmichaelsen

🌚
  • Phoenix
  • 06:29 (UTC -06:00)
View GitHub Profile
#!/bin/bash
let count0=0
for f in $(ls ./tests/*.txt); do
./a.out 0 < $f > ./tests/`basename $f .txt`.output;
diff -Bw ./tests/`basename $f .txt`.output ${f}.expected > ./tests/`basename $f .txt`.diff;
done;
for f in $(ls tests/*.txt); do
echo "========================================================";
function median($arr){
if($arr){
$count = count($arr);
sort($arr);
$mid = floor($count/2);
return ($arr[$mid]+$arr[$mid+1-$count%2])/2;
}
return false;
}
function average($arr){
## ATTN: run in ELEVETED powershell OR run as ADMINISTRATOR
## C:>\ powershell.exe
## PS C:>\ .\gen_machine_key.ps1
## copy output into your web.config > <system.web>
# Generates a <machineKey> element that can be copied + pasted into a Web.config file.
function Generate-MachineKey {
[CmdletBinding()]
param (
[ValidateSet("AES", "DES", "3DES")]
#!/bin/bash
# script for cloning repos from org
# and setting up remotes
# must have existing fork of target repo
if [ "$#" -ne 2 ]; then
echo "Usage: clone_repo.sh <git username> <repository name>"
else
git clone https://www.github.com/"$1"/"$2".git "$2"
@prmichaelsen
prmichaelsen / compile_run.sh
Created August 28, 2017 00:01
simple gist for compiling and packaging java programs with jar dependencies
#!bin/bash
HELPTEXT=`cat <<EOF
This script will neatly package your java project.
Recommended Project Structure
.. compile_run.sh bin lib src
Options:
-t|--target [string] the fully qualified name of the main class
-s|--standalone [flag] compile all dependencies into the final jar
@prmichaelsen
prmichaelsen / renderProps.jsx
Created September 8, 2017 04:03
an example of using renderProps as per Michael Jackson's demo
import React, { Component } from 'react';
export class Mouse extends React.Component {
state = { x: 0, y: 0 };
onMouseMove = (event) => {
this.setState(
{ x: event.clientX, y: event.clientY }
);
};
@prmichaelsen
prmichaelsen / countSubstr.c
Created September 15, 2017 18:04
with only stdio, count number of occurrences of a substring within a string
#include <stdio.h>
int countSubstr(char string[], char substring[])
{
int count = 0;
size_t i = -1;
while(string[++i])
{
int match = 1;
size_t j = 0;
var scripts = [
'https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.min.js'
];
scripts.forEach(source => {
var script = document.createElement('script');
script.src = source;
document.getElementsByTagName('head')[0].appendChild(script);
});
/**
* the stupidest way I could imagine to paginate
* an input array by pages with pageSize
*/
const paginate = (data, pageSize) => [
...Array(~~((data || []).length/pageSize)).keys()
].map(i => data.slice(i*pageSize , (i+1)*pageSize ));
// ~~ // floors a number
// [...Array(n).keys] => [0, 1, 2, ..., n - 2, n - 1]
#############################################################
# lotto.py
#############################################################
# Description: Compare avg return of 2018-10-23
# mega million lottery compared to number of tickets bought.
# Note: this script doesn't appear to implement the correct
# behavior for doing so. I think my math is off. Oh well, it
# was fun trying.
#############################################################