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 / CustomerController.cs
Created February 25, 2016 11:28 — forked from vkhorikov/CustomerController.cs
Handling failures and input errors in a functional way
[HttpPost]
public HttpResponseMessage CreateCustomer(string name, string billingInfo)
{
Result<BillingInfo> billingInfoResult = BillingInfo.Create(billingInfo);
Result<CustomerName> customerNameResult = CustomerName.Create(name);
return Result.Combine(billingInfoResult, customerNameResult)
.OnSuccess(() => _paymentGateway.ChargeCommission(billingInfoResult.Value))
.OnSuccess(() => new Customer(customerNameResult.Value))
.OnSuccess(
@jrgcubano
jrgcubano / Enable-wttr.in-for-PowerShell
Created February 25, 2016 15:08 — forked from chubin/Enable-wttr.in-for-PowerShell
How to enable wttr.in in a PowerShell console
# To enable ANSI sequences in a PowerShell console run the following commands.
# After that you can use wttr.in in you PowerShell just lake that:
# (curl http://wttr.in/ -UserAgent "curl" ).Content
#
# More on it:
# http://stknohg.hatenablog.jp/entry/2016/02/22/195644 (jp)
#
Add-Type -MemberDefinition @"
[DllImport("kernel32.dll", SetLastError=true)]
@jrgcubano
jrgcubano / slackpost
Created February 25, 2016 16:20 — forked from dopiaza/slackpost
Post a message to a Slack channel
#!/bin/bash
# Usage: slackpost <token> <channel> <message>
# Enter the name of your slack host here - the thing that appears in your URL:
# https://slackhost.slack.com/
slackhost=PUT_YOUR_HOST_HERE
token=$1
param(
[Parameter(Mandatory=$true)][string]$TaskPath,
[Parameter(Mandatory=$true)][string]$TfsUrl,
[PSCredential]$Credential = (Get-Credential),
[switch]$Overwrite = $false
)
# Load task definition from the JSON file
$taskDefinition = (Get-Content $taskPath\task.json) -join "`n" | ConvertFrom-Json
$taskFolder = Get-Item $TaskPath
dynamic samplefootballLegendObject = new ExpandoObject();
samplefootballLegendObject.FirstName = "Joro";
samplefootballLegendObject.LastName = "Beckham-a";
samplefootballLegendObject.Team = "Loko Mezdra";
samplefootballLegendObject.Salary = 380.5m;
samplefootballLegendObject.AsString = new Action(
() =>
Console.WriteLine("{0} {1} {2} {3}",
samplefootballLegendObject.FirstName,
@jrgcubano
jrgcubano / neo4jFriends.fsx
Created March 4, 2016 18:53 — forked from MartinBodocky/neo4jFriends.fsx
F# sample for Neo4j - Friends
#r "../packages/Neo4jClient.1.1.0.28/lib/net45/Neo4jClient.dll"
#r "../packages/Newtonsoft.Json.6.0.4/lib/net45/Newtonsoft.Json.dll"
open System
open System.Collections.Generic
open System.Linq
open Microsoft.FSharp.Quotations
open Microsoft.FSharp.Linq.RuntimeHelpers
open System.Linq.Expressions
@jrgcubano
jrgcubano / download-songs.sh
Created March 16, 2016 10:52 — forked from Nezteb/Download_Songs.sh
Downloads specified youtube videos as songs given text file.
#!/bin/bash
[ "$#" -eq 1 ] || { echo >&2 "Requires single text file (with youtube links on each line) name as argument."; exit 1; }
command -v youtube-dl >/dev/null 2>&1 || { echo >&2 "Install youtube-dl first."; exit 1; }
if [ ! -d "downloads" ]; then
mkdir downloads
fi
@jrgcubano
jrgcubano / setup.sql
Created March 17, 2016 08:38 — forked from robdmoore/setup.sql
Automated install of SQL Express from commandline
# If you want to give owner access to the whole server to a particular user account this is how
exec sp_addrolemember 'db_owner', 'NT AUTHORITY\NETWORK SERVICE';
GO
# If you want to idempotently ensure a particular database with name DatabaseName exists this is how
IF NOT db_id('DatabaseName') IS NOT NULL BEGIN
PRINT 'Creating database...'
CREATE DATABASE [DatabaseName]
PRINT 'Created database.'
@jrgcubano
jrgcubano / setup-cordova-phonegap.ps1
Created March 17, 2016 08:39 — forked from robdmoore/setup-cordova-phonegap.ps1
Scripted/Automated installation script to set up Cordova/PhoneGap and Android on Windows
# Run this in an elevated PowerShell prompt
<# This script worked on a fresh Windows Server 2012 VM in Azure and the following were the latest versions of each package at the time:
* Chocolatey 0.9.8.27
* java.jdk 7.0.60.1
* apache.ant 1.8.4
* android-sdk 22.6.2
* cordova 3.5.0-0.2.6
* nodejs.install 0.10.29
#>
# Note: there is one bit that requires user input (accepting the Android SDK license terms)
@jrgcubano
jrgcubano / UserValidator.cs
Created March 17, 2016 17:18 — forked from GrantByrne/UserValidator.cs
Using Fluent Validation with WPF - Dead Simple
using System.Text.RegularExpressions;
using FluentValidation;
using WpfFluentValidationExample.ViewModels;
namespace WpfFluentValidationExample.Lib
{
public class UserValidator : AbstractValidator<UserViewModel>
{
public UserValidator()
{