Skip to content

Instantly share code, notes, and snippets.

@bryandh
bryandh / Singleton.java
Last active October 7, 2015 19:35
Simple Singleton example
public class Singleton {
private static Singleton instance;
private Singleton(){
// empty by design
}
public static Singleton getInstance(){
if(instance == null)
instance = new Singleton();
@bryandh
bryandh / RavenDB index + Lucene query
Created October 16, 2015 20:25
Querying a RavenDB in Raven Studio
// First create a new index on the desired database.
// Say we have an Activity collection, we could write the following index:
from activity in docs.Activities
select new {
activity.Id
}
// After that, we can query the database using a combination of the created index and a Lucene query.
// In this example, we can specify the exact Id of the document we would like to query for.
Id: activities/1
@bryandh
bryandh / Program.cs
Created October 16, 2015 20:31
Simple console application interface, in this case it is used in a database setup project.
internal class Program
{
private static void Main(string[] args)
{
var welcome = @"
___ _ _ _ _ _ _ _ __
/ _ \ | | (_) (_)| | (_)| | | | / /
/ /_\ \ ___ | |_ _ __ __ _ | |_ ___ _ | |_ ___ _ __ | |/ / ___ _ _ ____ ___
| _ | / __|| __|| |\ \ / /| || __| / _ \| || __| / _ \| '_ \ | \ / _ \| | | ||_ / / _ \
| | | || (__ | |_ | | \ V / | || |_ | __/| || |_ | __/| | | || |\ \| __/| |_| | / / | __/
@bryandh
bryandh / auth0-migration-script.js
Created August 31, 2017 14:35
Auth0 login inter-tenant-migration-script
// Use this script in a connection within the Auth0 Tenant that you want to copy the user TO
// Use the variables defined in the login functions to specify the 'other' Auth0 Tenant that you want to copy the users FROM
function login (email, password, callback) {
// Require and set up all the Auth0 settings
var request = require('request'),
domain = 'OTHER TENANTS DOMAIN',
domain_uri = 'https://' + domain,
audience = 'OTHER TENANTS API AUDIENCE',
scope = 'openid profile email',
client_id = 'OTHER TENANTS CLIENT ID',
@bryandh
bryandh / evenly-distribute-list-items-horizontally.css
Last active September 27, 2017 06:18
Evenly distribute HTML list items horizontally using CSS
ul {
display: table;
width: 100%;
list-style: none;
}
ul li {
display: table-cell;
text-align: center;
}
@bryandh
bryandh / array-utilities.ts
Last active September 30, 2021 13:32
Typescript Array utilities
export class ArrayUtilities {
/**
* Groups a collection by a property to a Map type.
* @param collection The collection to group.
* @param groupKeyResolver Contains the property to group by, computed from a function.
* @returns Map key-value pair collection with given property as key and elements with that property as values.
*/
public static groupBy<K, T>(collection: T[], groupKeyResolver: (item: T) => K): Map<K, T[]> {
return collection.reduce(
(map: Map<K, T[]>, item: T) => {
@bryandh
bryandh / truncate.css
Created October 26, 2017 11:17
Truncate text with dots in CSS
.truncate {
width: 250px; // Not required as container's width is usually sufficient
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
@bryandh
bryandh / undo-remote-commit-instructions
Created December 8, 2017 10:53
Undo remote commit
1. `git rebase -i HEAD~2`
2. navigate to commit with arrows
3. press `d` twice to delete commit
4. enter `:wq` to save and quit (if it doesn’t let you, press escape first, and then enter this command)
5. force-push the branch to get rid of the remote commit
@bryandh
bryandh / commands.any
Last active May 8, 2020 08:31
Commands
// Lists the top-level global NPM packages
npm ls -g --depth=0
// Restart bluetooth service on Mac
sudo launchctl stop com.apple.blued
sudo launchctl start com.apple.blued
// Disable press-and-hold on Mac, essentially disabling the hold-to-select-special-character-version-of-letter
// Can be undone by using the same command with -bool true
defaults write -g ApplePressAndHoldEnabled -bool false
@bryandh
bryandh / .VS Code settings.md
Last active May 18, 2018 07:53
VS Code settings

My personal VS Code settings