Skip to content

Instantly share code, notes, and snippets.

public class UserModelBinder : IModelBinder
{
public Func<UserDataService> UserData { get; set; }
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
Guid UserID = (Guid)Membership.GetUser().ProviderUserKey;
User u = UserData().GetUser(UserID);
@hgirish
hgirish / RouteConfig.cs
Last active November 3, 2016 05:26
RouteConfig for ignoring bot requests
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*vti_inf}", new { vti_inf = @"(.*/)?_vti_inf.html(/.*)?" });
routes.IgnoreRoute("{*vti_rpc}", new { vti_rpc = @"(.*/)?_vti_rpc(/.*)?" });
routes.IgnoreRoute("{*allphp}", new { allphp = @".*\.php(/.*)?" });
routes.IgnoreRoute("{*allcgi}", new { allcgi = @".*\.cgi(/.*)?" });
@hgirish
hgirish / cloudflare-remoteaddress-coldfusion.txt
Last active November 20, 2022 07:04
Find Remote IP Address in Coldfusion when Cloudflare
<cfset remoteAddress = getHttpRequestData().headers["CF-Connecting-IP"] >
<cfif remoteAddress eq ''>
<cfset remoteAddress = getHttpRequestData().headers["X-Forwarded-For"] >
</cfif>
<cfif remoteAddress eq ''>
<cfset remoteAddress = cgi.REMOTE_ADDR >
</cfif>
@hgirish
hgirish / Antiforgery-X-Frame-Options.txt
Last active January 26, 2016 05:59
AntiforgeryToken adds X-Frame-Options per token, resulting in large header size, causing error 520 in CloudFlare
// AntiForgeryToken automatically adds x-Frame-Options SAMEORIGIN for each token
// resulting in
// X-Frame-Options SAMEORIGIN, SAMEORIGIN, SAMEORIGIN, SAMEORIGIN, SAMEORIGIN, SAMEORIGIN, SAMEORIGIN....
// This happens when there is update form inside the list and each update form have Antiforgerytoken
// If hosted on CloudFlare, this will produce Error 520, if header size becomes larger than 32KB
// Adding following will fix the issue.
// Global.ascx.cs
protected void Application_Start()
{
AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
@hgirish
hgirish / nano-shortcuts.txt
Created April 28, 2016 04:04
Nano Keyboard Shortcuts
The nano editor is designed to emulate the functionality and ease-of-use
of the UW Pico text editor. There are four main sections of the editor.
The top line shows the program version, the current filename being
edited, and whether or not the file has been modified. Next is the main
editor window showing the file being edited. The status line is the
third line from the bottom and shows important messages. The bottom two
lines show the most commonly used shortcuts in the editor.
The notation for shortcuts is as follows: Control-key sequences are
notated with a caret (^) symbol and can be entered either by using the
$files = Get-ChildItem "app*.config" -Recurse
$find = 'some-string-to-find'
$replace = 'some-string-to-replace-with'
Get-ChildItem $files -Recurse |
select -ExpandProperty fullname |
foreach {
If(Select-String -Path $_ -SimpleMatch $find -quiet){
/// Script to remove project_readme.html from newly created asp.net web application project
/// using Package Manager Console in visual studio.
// To Open nuget_profile.ps1 from package manager console
// notepad $profile
// In NuGet_profile.ps1
set-alias rpr Remove-Project-Readme
Function Remove-Project-ReadMe
@hgirish
hgirish / S3Uploader.cs
Created October 18, 2016 05:21
Code to Upload file using AmazonS3Client TransferUtility
using System;
using System.IO;
using System.Threading.Tasks;
using Amazon.S3;
using Amazon.S3.Model;
using Amazon.S3.Transfer;
namespace AWSDemo.Models
{
public class S3Uploader
@hgirish
hgirish / unicode_print.py
Last active May 26, 2017 02:00
Windows UnicodeEncodeError: 'charmap' codec can't encode character
# taken from https://forum.sublimetext.com/t/windows-st3-python-3-unicode-output/15261/4
import sys
from io import TextIOWrapper
sys.stdout = TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
@hgirish
hgirish / gist:a247fcc3f74b9ea1044bdfccc5bffc51
Last active December 13, 2018 20:06
Vue.js router-link css class using bootstrap 4
<nav>
<ul class="nav nav-pills">
<li class="nav-item">
<router-link to="/" class="nav-link" exact-active-class="active"
>Home</router-link
>
</li>
<li class="nav-item">
<router-link
class="nav-link"