Skip to content

Instantly share code, notes, and snippets.

View prmichaelsen's full-sized avatar
🌚

Patrick Michaelsen prmichaelsen

🌚
  • 00:22 (UTC -06:00)
View GitHub Profile
@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 / 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
#!/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"
## 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")]
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){
#!/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 "========================================================";
def maxProfit ( self, prices ):
previous_delta = 0
delta = 0
max_profit = 0
for i in range( 1 , len ( prices ) ) :
previous_delta = delta
delta = prices[ i ] - prices [ i - 1 ]
int maxProfit(int* prices, int n) {
int previous_delta = 0;
int delta = 0;
int max_profit = 0;
for ( int i = 1 ; i < n ; i ++ )
{
previous_delta = delta;
delta = prices[ i ] - prices [ i - 1 ];
WHILE no swaps performed
FOR pair of elements
IF pair is out of order
swap pair
//************************************************************************//
// one_var_bubble_sort.c //
//************************************************************************//
//
// AUTHOR: Patrick Michaelsen
// EMAIL: [email protected]
// [email protected]
// WEBSITE: PatrickMichaelsen.com
//
// DESCRIPTION: This algorithm bubble sorts an array of