Skip to content

Instantly share code, notes, and snippets.

Patrick Roza patroza

Block or report user

Report or block patroza

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@patroza
patroza / twoSum.scala
Last active Nov 4, 2019 — forked from stzr1123/twoSum.scala
Interview type problems
View twoSum.scala
import scala.annotation.tailrec
object ShittySolution {
// Given an array of integers, return indices of the two numbers such that they add up to a specific target.
//
// You may assume that each input would have exactly one solution, and you may not use the same element twice.
// https://leetcode.com/problems/two-sum/
// NB: More efficient solution would iterate once over the array and keep a Map of values and indicies
def twoSum(nums: Array[Int], target: Int): Array[Int] = {
View 1.useMatchFetch.js
import { useState, useEffect } from "react";
export const render = result => match =>
result.pending ? match.pending()
: result.error ? match.error(result.error)
: result.data ? match.data(result.data)
: null // prettier-ignore
export const useMatchFetch = url => {
const [result, setResult] = useState({ pending: true, initial: true });
@patroza
patroza / controller-presenter-interactor.cs
Last active Jun 4, 2019
Literal Controller/Presenter/Interactor implementation sample (naive), I prefer MediatR instead for most cases :) from http://www.plainionist.net/Implementing-Clean-Architecture-Controller-Presenter/
View controller-presenter-interactor.cs
// "controller"
(ctx, next) => {
let presenter = new Presenter(ctx)
let interactor = new Interactor(presenter)
interactor.handle(getRequestFrom(ctx))
}
class Presenter {
constructor(ctx) { this.ctx = ctx }
present(response) {
@patroza
patroza / docker-compose.sh
Last active Jul 5, 2017
Running windows commands with .envrc (dynamically converting exports) from WSL (Bash on Windows)
View docker-compose.sh
#!/bin/bash
command=`basename "$0"`
run-windows-command "$command" "$@"
View docker
#!/bin/bash
command=`basename "$0"`
run-windows-command "$command" "$@"
View Tdf.cs
public static IObservable<TResult> FromTdf<T, TResult>(this IObservable<T> source,
Func<IPropagatorBlock<T, TResult>> blockFactory) => Observable.Create<TResult>(observer => {
var block = blockFactory();
var dsp1 = block.AsObservable().Subscribe(observer.OnNext);
var dsp2 = source.Subscribe(block.AsObserver());
return new CompositeDisposable {dsp2, dsp1};
});
public static IObservable<TResult> FromTdf<T, TResult>(this IObservable<T> source,
IPropagatorBlock<T, TResult> block) => source.FromTdf(() => block);
@patroza
patroza / SpecsFor.cs
Created Jan 25, 2016
A slightly improved SpecsFor class
View SpecsFor.cs
/// <summary>
/// A more closed version of the official SpecsFor class,
/// with some additional helpers
/// </summary>
/// <typeparam name="T"></typeparam>
public abstract class SpecsFor<T> : SpecsFor.SpecsFor<T>, IAnd<T> where T : class
{
protected abstract override void Given();
protected abstract override void When();
public sealed override void TearDown() => base.TearDown();
View linq.d.ts
declare module 'linq4es2015/linq' {
export default class Linq {
static setExtensions(): void;
static repeat<T>(element: T, count: number): Enumerable<T>;
static range(start: number, count: number): Enumerable<number>;
static empty<T>(): Enumerable<T>;
static asEnumerable<T>(source: T[]): Enumerable<T>;
static aggregate(): any;
static all(): any;
View gist:f58e682c5bac47ff5c6f
/// <summary>
/// Uses character by character parsing for StandardOutput and StandardError, so \r can be processed.
/// Uses observables instead of eventhandlers. Do not call BeginReadStandardOutput and BeginReadStandardError etc
/// </summary>
public class ReactiveProcess : Process
{
readonly CompositeDisposable _observables;
readonly Subject<string> _standardErrorObserable;
readonly Subject<string> _standardOutputObserable;
View Context
readonly ICollection<Action> _transactionCallbacks = new Collection<Action>();
public override int SaveChanges() {
int r;
try {
ExecuteDomainEvents();
r = base.SaveChanges();
} catch (Exception) {
_transactionCallbacks.Clear();
throw;
You can’t perform that action at this time.