Skip to content

Instantly share code, notes, and snippets.

View bradynpoulsen's full-sized avatar

Bradyn Poulsen bradynpoulsen

View GitHub Profile
@bradynpoulsen
bradynpoulsen / apache-2-cla-pt1-individual.md
Last active December 7, 2019 08:40
Contributor License Agreement for my Open-Source Projects that use the Apache 2.0 license

Individual Contributor License Agreement

Thank you for your interest in contributing to Bradyn Poulsen's open-source project ("We" or "Us").

The purpose of this contributor agreement ("Agreement") is to clarify and document the rights granted by contributors to Us. To make this document effective, please follow the instructions on your Pull Request.

How to use this Contributor Agreement

If You are an employee and have created the Contribution as part of your employment, You need to have Your employer approve this Agreement or sign the Entity version of this document. If You do not own the Copyright in the entire work of authorship, any other author of the Contribution should also sign this. This license is available online at https://gist.github.com/bradynpoulsen/0a6e9203322f71c65d61f2240103e06c.

@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 {
@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 / 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 / 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 / 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 / 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 #
# #
########################################################################################

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:

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
@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