Skip to content

Instantly share code, notes, and snippets.

View phrz's full-sized avatar

Paul Herz phrz

View GitHub Profile
@phrz
phrz / peers.sh
Created January 16, 2018 16:07
A quick bash alias for finding peers on a network with nmap.
alias peers="nmap -sn 192.168.1.0/24|python3 -c $'import sys\n[print(\' \'.j oin(s.split(\' \')[4:]),end=\'\') for s in sys.stdin.readlines()[2::2]]'"
@phrz
phrz / reverse_string.c
Created January 16, 2018 15:18
Reverses a string in C while minding buffer sizes.
void reverse(char* string, char* buffer, size_t buffer_limit) {
if(buffer_limit < 1) {
return;
}
size_t len = strnlen(string, buffer_limit);
if(len == 0) {
buffer[0] = '\0';
return;
}
buffer[len] = '\0';
@phrz
phrz / coderunner_haskell.sh
Last active January 16, 2018 12:42
A CodeRunner 2 for Mac compile script to enable execution of Haskell.
#!/bin/bash
# This is a CodeRunner compile script. Compile scripts are used to compile
# code before being run using the run command specified in CodeRunner
# preferences. This script is invoked with the following properties:
#
# Current directory: The directory of the source file being run
#
# Arguments $1-$n: User-defined compile flags
#
# Environment: $CR_FILENAME Filename of the source file being run
@phrz
phrz / UIView+Edges.swift
Created December 20, 2017 02:06
Some extensions to improve the developer experience of dealing with UIKit constraints (and a LayoutChain for stacking without spacing)
//
// UIView+Edges.swift
// Centigrade
//
// Created by Paul Herz on 2017-11-02.
// Copyright © 2017 Centigrade. All rights reserved.
//
import UIKit
alias peers="nmap -sn 192.168.1.0/24|python3 -c $'import sys\n[print(\' \'.join(s.split(\' \')[4:]),end=\'\') for s in sys.stdin.readlines()[2::2]]'"
template<typename T>
class ConcurrentQueue {
protected:
mutable std::mutex queue_mutex;
std::queue<T> queue;
[[nodiscard]] auto getLock() {
return std::lock_guard<std::mutex>(this->queue_mutex);
}
public:
# This only works for RSA: checks the shared modulus
# of a CSR, Cert, and Private Key
openssl rsa -noout -modulus -in FILE.key
openssl req -noout -modulus -in FILE.csr
openssl x509 -noout -modulus -in FILE.cer
template<
typename... T,
typename std::enable_if<std::is_same<T&&..., Point>::value>::type
>
Point addPoints(T&&... points) {
// all arguments are guaranteed to be type Point
}
@phrz
phrz / euler11.py
Created December 13, 2017 18:58
Project Euler Problem #11, golfed to hell (369B not counting comments and matrix string)
'''
Project Euler
Problem 11
In the 20×20 grid below, four numbers along a diagonal line have been marked in red.
[omitted]
The product of these numbers is 26 × 63 × 78 × 14 = 1788696.
What is the greatest product of four adjacent numbers in the same direction (up, down, left, right, or diagonally) in the 20×20 grid?
ANSWER
@phrz
phrz / benchmark.py
Created December 13, 2017 18:11
Some snippets for testing performance
# duration_string(seconds)
# takes a float of seconds and
# returns a formatted unit string
# (microseconds up to years)
#
# with timer():
# a context that prints the time
# of its inner block
#
# @benchmark() or @benchmark(iterations)