Skip to content

Instantly share code, notes, and snippets.

View jrgcubano's full-sized avatar

Jorge Rodríguez Galán jrgcubano

View GitHub Profile
// library or otherwise
// {
type Func<T, TResult> = (value: T) => TResult;
type Predicate<T> = Func<T, boolean>;
function compose<TIn, TMiddle, TOut>(f: Func<TMiddle, TOut>, g: Func<TIn, TMiddle>) {
return (value: TIn) => f(g(value));
}
// 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 / 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 / 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
{
export interface SortedArrayOpts {
filter?: Function;
compare?: Function | string;
unique?: boolean;
resume?: boolean;
}
export class SortedArray<T> extends Array<T> {
private readonly _filter: Function;
private readonly _compare: Function;
# Install script for Kristoffer
# Created 06.08.2015
ECHO Installing apps
ECHO Configure chocolatey
choco feature enable -n allowGlobalConfirmation
#choco install visualstudiocode
choco install notepadplusplus
{
"version": "0.2.0",
"configurations": [
{
"name": "StartCake",
"type": "mono",
"request": "launch",
"program": "${workspaceRoot}/tools/Cake/Cake.exe",
"runtimeArgs": [
"--debug",