Skip to content

Instantly share code, notes, and snippets.

View jrgcubano's full-sized avatar

Jorge Rodríguez Galán jrgcubano

View GitHub Profile
@jrgcubano
jrgcubano / ValueObject.cs
Created August 20, 2017 17:38
CQRS Example parts (ValueObject, ...)
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace EventFlow.ValueObjects
{
public abstract class ValueObject
{
// Licensed under the MIT license with <3 by GitHub
/// <summary>
/// An exponential back off strategy which starts with 1 second and then 4, 9, 16...
/// </summary>
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
public static readonly Func<int, TimeSpan> ExponentialBackoff = n => TimeSpan.FromSeconds(Math.Pow(n, 2));
/// <summary>
/// Returns a cold observable which retries (re-subscribes to) the source observable on error up to the
@jrgcubano
jrgcubano / cronToRxExample.cs
Created August 9, 2017 07:17
Cron to observable Rx, retry and circuit breaker
// via https://stackoverflow.com/questions/26597393/cron-observable-sequence
// and cloud patterns (circuit breaker, retry, etc)
https://github.com/myquay/Solve.Reliability.Rx
// convert cron to time https://github.com/HangfireIO/Cronos
public static IObservable<int> Cron(string cron, IScheduler scheduler)
{
var schedule = CrontabSchedule.Parse(cron);
return Observable.Generate(0, d => true, d => d + 1, d => d,
@jrgcubano
jrgcubano / CSRGenerator.cs
Created July 27, 2017 10:38 — forked from Maverik/CSRGenerator.cs
CSR Generator Snippet for Linqpad (C#)
// this snippet can be easily used in any normal c# project as well by simply removing the .Dump() methods
// and saving the output into a variable / file of your choice.
// you'll need to add BouncyCastle.Crypto nuget to use this.
// tested on 1.8.1
// OUTPUTS: CSR, Private Key, Public Key, Self-signed Certificate
using Org.BouncyCastle.Asn1;
using Org.BouncyCastle.Asn1.Cms;
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.X509;

Reading data before application startup in Angular 2

In this demonstration I will show you how to read data in Angular2 final release before application startup. You can use it to read configuration files like you do in other languages like Java, Python, Ruby, Php.

This is how the demonstration will load data:

a) It will read an env file named 'env.json'. This file indicates what is the current working environment. Options are: 'production' and 'development';

b) It will read a config JSON file based on what is found in env file. If env is "production", the file is 'config.production.json'. If env is "development", the file is 'config.development.json'.

@jrgcubano
jrgcubano / httpService.ts
Created June 25, 2017 23:03 — forked from cloudmark/httpService.ts
HttpService
export class HttpService {
constructor(private http: Http) {}
public getSingle<T>(clazz: { new(): T }, url: string, headers?: {}): Promise<T> {
return new Promise((resolve, reject) => {
this.http.get(url, this.getHeaders(headers)).toPromise().then((response: any) => {
let body = response.json();
if (body) {
resolve(MapUtils.deserialize(clazz, body));
} else {
@jrgcubano
jrgcubano / .editorconfig
Created June 12, 2017 09:37
Check EditorConfig
# EditorConfig is awesome: http://EditorConfig.org
root = true
[*]
charset = utf-8
[{package.json}]
indent_style = space
indent_size = 2
@jrgcubano
jrgcubano / tmux-cheatsheet.markdown
Created May 31, 2017 20:23 — forked from MohamedAlaa/tmux-cheatsheet.markdown
tmux shortcuts & cheatsheet

tmux shortcuts & cheatsheet

start new:

tmux

start new with session name:

tmux new -s myname
@jrgcubano
jrgcubano / SlackClient.cs
Created May 9, 2017 08:45 — forked from jogleasonjr/SlackClient.cs
A simple C# class to post messages to a Slack channel. You must have the Incoming WebHooks Integration enabled. This class uses the Newtonsoft Json.NET serializer available via NuGet. Scroll down for an example test method and a LinqPad snippet. Enjoy!
using Newtonsoft.Json;
using System;
using System.Collections.Specialized;
using System.Net;
using System.Text;
//A simple C# class to post messages to a Slack channel
//Note: This class uses the Newtonsoft Json.NET serializer available via NuGet
public class SlackClient
{
@jrgcubano
jrgcubano / typescript-navigable-object-example.ts
Created May 6, 2017 22:02
Navigable Typescript object using arrows
class NavigableObject<T> {
constructor(private obj: T, private path: string[] = []) { }
To<R>(p: (x: T) => R): NavigableObject<R> {
return new NavigableObject<R>(p(this.obj),
this.path.concat(this.getPropName(p)));
}
getPath() {
return this.path;