Skip to content

Instantly share code, notes, and snippets.

View joaofx's full-sized avatar
😁

Joao Carlos Clementoni joaofx

😁
View GitHub Profile
@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);
@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);
}
ObjectFactory.Initialize(x =>
{
x.Scan(scan =>
{
scan.TheCallingAssembly();
scan.WithDefaultConventions();
scan.ConnectImplementationsToTypesClosing(typeof(AbstractValidator<>));
});
});
@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; }
@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
{
@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;
@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);
@pdwetz
pdwetz / gist:4677630
Last active December 22, 2016 16:53
Useful little bits for FubuMVC; rather than dig through source, keeping them here for quick reference. I'll eventually post an article with them that's better for public consumption.
// If using FubuAthentication, update auth ticket as needed (e.g. account creation or key updated)
private readonly IAuthenticationSession _auth;
public SomeController(IAuthenticationSession auth) { _auth = auth; }
_auth.MarkAuthenticated(user.Email);
// If using FubuAuthentication, make route available to anonymous users
[NotAuthenticated]
public FubuContinuation SomeRoute(SomeRouteInputModel input)
{
// Use a continuation to redirect to input-less page
(function ($) {
$.fubuvalidation.Processor.findElementsWith(function(context) {
var element = $("#" + context.key, context.form);
if (element.size() == 0) {
return;
}
context.element = element;
});
$.fubuvalidation.Processor.findElementsWith(function(context) {
var element = $("[name=" + context.key + "]", context.form);
@rpgmaker
rpgmaker / gist:4405468
Last active August 11, 2022 14:24
Expression Parser and example.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Concurrent;
using System.Linq.Expressions;
using System.Collections;
namespace ExpressionParser {