Skip to content

Instantly share code, notes, and snippets.

View bradynpoulsen's full-sized avatar

Bradyn Poulsen bradynpoulsen

View GitHub Profile
@bradynpoulsen
bradynpoulsen / .bashrc
Last active August 29, 2015 13:56
Bash :: Exit status indicator in command line prompt
# This is a nearly identical copy and paste how I have my status indicators work in terminal
export PROMPT_COMMAND=prompt
function prompt {
local EXIT=$? # This MUST be first to get exit code of last command
# Text Colors, I chose to use tput to get my colors
local BL=`tput setaf 0` # Black
local RD=`tput setaf 1` # Red
@bradynpoulsen
bradynpoulsen / project.rb
Created April 2, 2014 22:53
ActiveModel Serializer Embedded Associations via ?embed=rel1,rel2
class Project < ActiveRecord::Base
belongs_to :client
has_many :user_projects
has_many :users, through: :users_projects
end
function bash_prompt {
local EXIT="$?"
# Text Color
# local BL="\\[`tput setaf 0`\\]" # Black
local RD="\\[`tput setaf 1`\\]" # Red
local GR="\\[`tput setaf 2`\\]" # Green
local YE="\\[`tput setaf 3`\\]" # Yellow
local BU="\\[`tput setaf 4`\\]" # Blue
# local MA="\\[`tput setaf 5`\\]" # Magenta

Keybase proof

I hereby claim:

  • I am bradynpoulsen on github.
  • I am bradynpoulsen (https://keybase.io/bradynpoulsen) on keybase.
  • I have a public key whose fingerprint is 26B1 25F3 D315 1CBE 19DF D6B3 7B5C 787E C683 192E

To claim this, I am signing this object:

@bradynpoulsen
bradynpoulsen / pre-push.sh
Last active January 21, 2016 01:42
Executes PHP CodeSniffer using your project's phpcs.xml settings
#!/bin/sh
########################################################################################
# #
# Created by Bradyn Poulsen #
# Install using CURL: #
# #
# curl -L -o .git/hooks/pre-push https://git.io/vz4TW && chmod +x .git/hooks/pre-push #
# #
########################################################################################
@bradynpoulsen
bradynpoulsen / generatePrivateKey.bash
Created June 30, 2016 22:06
Generate a Private Key using OpenSSL with PHP
php -r '$key = openssl_pkey_new(); openssl_pkey_export($key, $privateKey); echo $privateKey;'
@bradynpoulsen
bradynpoulsen / 1-signup.php
Last active January 22, 2017 12:10
Basic PHP Password Hashing
<?php
$user = new User;
$user->email = 'foo@example.com';
$user->password_digest = password_hash('mypassword', PASSWORD_DEFAULT);
$user->save();
@bradynpoulsen
bradynpoulsen / build.gradle.kts
Created September 21, 2017 08:53
Gradle build scripts in Kotlin
import org.gradle.jvm.tasks.Jar
plugins {
application
kotlin(module = "jvm")
}
repositories {
jcenter()
}
@bradynpoulsen
bradynpoulsen / java-map-vs-flatMap.java
Created June 27, 2018 21:38
Compares the difference between map and flatMap in Java 8
import java.util.function.Function;
import java.util.stream.Stream;
public class Foo {
void test() {
Function<Integer, Stream<Integer>> transformer = it -> Stream.of(it * 10, it * 100, it * 1000);
Stream<Integer> myInts = Stream.of(1, 2, 3);
// contains [ [10, 100, 1000], [20, 200, 2000], [30, 300, 3000] ]
@bradynpoulsen
bradynpoulsen / MutexPool.kt
Created February 12, 2019 15:12
Mutex pool that can be used to limit the number of workers operating at the same time
import kotlinx.coroutines.selects.select
import kotlinx.coroutines.sync.Mutex
class MutexPool(val pool: Set<Mutex>) {
constructor(poolSize: Int) : this((1..poolSize).map { Mutex() }.toSet())
suspend inline fun <R> withLock(crossinline block: () -> R): R = select {
pool.forEach {
it.onLock { lockedMutex ->
try {