View startup_extension.cs
public static IApplicationBuilder Use401ForUnauthorizedApiCalls(this IApplicationBuilder app)
{
app.Use(async (context, next) =>
{
if (context.Request.Path.Value.Contains("/api") &&
(context.User == null ||
context.User.Identity == null ||
!context.User.Identity.IsAuthenticated))
{
context.Response.StatusCode = 401;
View Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
View replica_set.sh
jarvis:PRIMARY> rs.status()
{
"set" : "jarvis",
"date" : ISODate("2015-05-20T19:15:31Z"),
"myState" : 1,
"members" : [
{
"_id" : 0,
"name" : "[SERVER1]:27017",
"health" : 1,
View mongo_to_dynamic.cs
public static class MongoDynamic
{
private static System.Text.RegularExpressions.Regex objectIdReplace = new System.Text.RegularExpressions.Regex(@"ObjectId\((.[a-f0-9]{24}.)\)", System.Text.RegularExpressions.RegexOptions.Compiled);
/// <summary>
/// deserializes this bson doc to a .net dynamic object
/// </summary>
/// <param name="bson">bson doc to convert to dynamic</param>
public static dynamic ToDynamic(this BsonDocument bson)
{
var json = objectIdReplace.Replace(bson.ToJson(), (s) => s.Groups[1].Value);
View foreach_with_index.cs
foreach ( var it in someCollection.Select((x,i) => new { Value = x, Index=i }) )
{
if ( it.Index > SomeNumber) {// }
}
//or
public static void Each<T>( this IEnumerable<T> ie, Action<T, int> action )
{
var i = 0;
View parameterize.py
def parameterize(string_to_clean, sep = '-'):
parameterized_string = unicodedata.normalize('NFKD', string_to_clean).encode('ASCII', 'ignore').decode()
parameterized_string = re.sub("[^a-zA-Z0-9\-_]+", sep, parameterized_string)
if sep is not None and sep is not '':
parameterized_string = re.sub('/#{re_sep}{2,}', sep, parameterized_string)
parameterized_string = re.sub('^#{re_sep}|#{re_sep}$', sep, parameterized_string, re.I)
return parameterized_string.lower()
View on.md

1. Create the shell script

#!/bin/bash
curl -X POST --data-urlencode "task=$1" https://api.workingon.co/hooks/incoming?token={YOUR WORKING ON INTEGRATION TOKEN} >/dev/null
echo "Task sent!";

Save this wherever you want (I am saving under my $HOME folder on Windows), you don´t even need to add a file extension to it ;)

View job.ps1
$jobItems = "a", "b", "c", "d", "e"
$jobMax = 2
$jobs = @()
$jobWork = {
param ($MyInput)
if ($MyInput -eq "d") {
throw "an example of an error"
} else {
write-output "Processed $MyInput"
View cpf_cnpj_validators.rb
#------------------------------------------------------------------------------
# Rotinas para verificação de CPF e CNPJ
# Linguagem: Ruby
# Escrito por: André Camargo < andre@boaideia.inf.br > http://blog.boaideia.inf.br
# Use, copie, melhore a vontade! Patches são bem-vindos...
#------------------------------------------------------------------------------
def check_cpf(cpf=nil)
return false if cpf.nil?
nulos = %w{12345678909 11111111111 22222222222 33333333333 44444444444 55555555555 66666666666 77777777777 88888888888 99999999999 00000000000}
View Gemfile
source :rubygems
gem 'sinatra'
gem 'json'
gem 'omniauth'
gem 'omniauth-oauth2'
gem 'omniauth-github'
# gem 'omniauth-att', :path => File.expand_path("./../../omniauth-att", __FILE__)
gem 'thin'