Skip to content

Instantly share code, notes, and snippets.

View joaofx's full-sized avatar
😁

Joao Carlos Clementoni joaofx

😁
View GitHub Profile
@jbogard
jbogard / Slice.cs
Last active December 15, 2015 05:19
Slice and dice baby
public static IEnumerable<IEnumerable<TSource>> Slice<TSource>(
this IEnumerable<TSource> sequence,
int maxItemsPerSlice)
{
if (maxItemsPerSlice <= 0)
{
throw new ArgumentOutOfRangeException("maxItemsPerSlice", "maxItemsPerSlice must be greater than 0");
}
var slice = new List<TSource>(maxItemsPerSlice);
@benschwarz
benschwarz / csrf-token.js
Created April 7, 2013 23:11
Set the CSRF token for Rails when doing Ajax requests
define( ['jquery'], function ( $ ) {
var token = $( 'meta[name="csrf-token"]' ).attr( 'content' );
$.ajaxSetup( {
beforeSend: function ( xhr ) {
xhr.setRequestHeader( 'X-CSRF-Token', token );
}
});
return token;
@KevM
KevM / endpoints.cs
Last active December 22, 2016 16:55
FubuContinuations do not redirect when a simple checkbox is present on the input model?
public class get_handler
{
public SignInModel Execute(SignInRequest request)
{
return new SignInModel {ReturnUrl = request.ReturnUrl, LoginFailed = request.LoginFailed};
}
}
public class post_handler
{
@KevM
KevM / InputModel.cs
Last active October 14, 2016 20:17
FubuMVC: Model binding challenged. My scenario seems to be what the NestedObjectPropertyBinder was created for but I cannot get it working The endpoint using this input model is binding everything perfectly except the Address properties
public class SitePostRequest
{
public int DatabaseIdentifier { get; set; }
[Required]
public string SiteId { get; set; }
[Required]
public string Name { get; set; }
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.ConnectImplementationsToTypesClosing(typeof(AbstractValidator<>));
});
});
@jbogard
jbogard / gist:6690905
Last active December 23, 2015 20:39
Fun with tests.
namespace Accounts
{
namespace NewAccounts
{
public class When_creating_a_new_account {
Account account = new Account();
public void Does_not_have_any_subscriptions() {
account.Subscriptions.Count.ShouldEqual(0);
}
@davidfowl
davidfowl / failregex.cs
Last active June 22, 2016 01:17
Here's a regex that will max out your CPU (just one)
using System;
using System.Text.RegularExpressions;
namespace RegexFail
{
class Program
{
static void Main(string[] args)
{
var urlPattern = new Regex(@"(?i)\b((?:[a-z][\w-]+:(?:/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'"".,<>?«»“”‘’]))", RegexOptions.Compiled | RegexOptions.IgnoreCase);
@jbenet
jbenet / simple-git-branching-model.md
Last active May 3, 2025 18:07
a simple git branching model

a simple git branching model (written in 2013)

This is a very simple git workflow. It (and variants) is in use by many people. I settled on it after using it very effectively at Athena. GitHub does something similar; Zach Holman mentioned it in this talk.

Update: Woah, thanks for all the attention. Didn't expect this simple rant to get popular.

@tamoyal
tamoyal / gist:10441108
Created April 11, 2014 04:39
Create super user and database user in Mongo 2.6
# Create your superuser
$ mongo
> use admin
> db.createUser({user:"someadmin",pwd:"secret", roles:[{role:"root",db:"admin"}]})
> exit
# Alias for convenience (optional and at your own risk)
$ echo 'alias mongo="mongo --port 27017 -u someadmin -p secret --authenticationDatabase admin"' >> ~/.bash_profile
$ source ~/.bash_profile
readonly ICollection<Action> _transactionCallbacks = new Collection<Action>();
public override int SaveChanges() {
int r;
try {
ExecuteDomainEvents();
r = base.SaveChanges();
} catch (Exception) {
_transactionCallbacks.Clear();
throw;