Skip to content

Instantly share code, notes, and snippets.

@Injac
Injac / ajax to mvc
Created February 14, 2014 15:11
Ajax request from jQuery to Web Api - this is how to do it.
$.ajax({
url: 'YOUR WEB API URL',
type: 'POST/PUT/WHATEVER',
dataType: 'json',
contentType: 'application/json; charset=utf-8', //IMPORTANT!
data: JSON.stringify(appId),
success: function () { alert('COMPLETED!'); },
error: function (xhr, message, error) {
alert(error);
}
@Injac
Injac / RequireHttpsWebApi
Created February 14, 2014 13:52
Web API based HTTPS Authorization Filter Attribute. Put that attribute on your Web API controller class.
public class RequireHttpsWebApiAttribute : AuthorizationFilterAttribute
{
public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
{
if (actionContext.Request.RequestUri.Scheme != Uri.UriSchemeHttps)
{
actionContext.Response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden)
{
ReasonPhrase = "HTTPS Required"
@Injac
Injac / nudeCheck.py
Created January 27, 2014 01:50
Check for nudity using Python.
import os
import glob
import nude
from nude import Nude
path = '[Your image path]'
for infile in glob.glob(os.path.join(path,'*.png')) :
n = Nude(infile)
n.parse()
@Injac
Injac / Just a scratch file
Created December 16, 2013 10:44
Encrypted JSON DATA
áìêwˆóu…íV^²òØ0­O¸*W.±­d-
ÃSdáoÆA–…'Ùð"ù³®ÙpXž=ÉÁú%u†b“hÓúY–ooY­¢d7EÑšmÈ‹“8ÈXãÍ/ÛÜz*ìý’†£C4P’Ae…äÇ÷Éá÷{ÙQt´Á¦¹ÃR'ãNëÙø±ª
RÐ.”F$Ïó"ɏc©¨ÖIÁŒ"1bå»+çr?£ûo¹’âH^ScßðAç†_0oQ×EËgfP!"ÿP^²õDNÙÊÉõüηŽKTõ~—O6ô;1}Yw9…ƒ´«}Tw…\z09M&ã’ݏA¢Ïg§ çH&OÊ×ÔØ9m&ÐE¢´×s„OØÐÚ¢$Š(%“ g"«fú”7ЩÕc¡€ˆ'njŸ
@Injac
Injac / ZipCodeValidator
Last active December 31, 2015 01:28
Check Zip and postal codes (or whatever) based on ISO values and regular expressions
/// <summary>
/// Validate zip code value
/// using ISO country code.
/// </summary>
public class ZipCodeValidator
{
private Dictionary<string, string> countryList;
public Dictionary<string, string> CountryList
{
@Injac
Injac / BootTwoToThree.ps
Created September 11, 2013 23:34
Little PowerShell script to update your bootstrap 2 Project to Bootstrap 3. Please use carefully and get a copy of your Project files and run it on the copy! No warranty that it will work or not destroy your work! Replace [FULL PATH TO YOUR HTML FILE FOLDER] with the full path to your Project files, and [FULL PATH TO YOUR LOGFILE] with the full …
Get-ChildItem '[FULL PATH TO YOUR HTML FILE FOLDER]' *.html -recurse |
Foreach-Object {
$c = ($_ | Get-Content)
$logFile = "[FULL PATH TO YOUR LOGFILE]";
$output = "Modifiying file: " + $_.FullName
$output | out-file $LogFile -Append
@Injac
Injac / bootstrap 3.0 MVC
Last active December 22, 2015 19:49
Bootstrap 3.0 Version of _Layout.cshtml and index.cshtml for Visual Studio 2013 MVC project.
<!-- _LAYOUT.CSHTML -->
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Injac
Injac / JSONPMediaTypeFormatter
Last active December 21, 2015 15:49
A JSONP media-type formatter for ASP .NET WebApi (latest stable version). Copy the class and add this to your Global.asax.s var config = GlobalConfiguration.Configuration; config.Formatters.Add(new JsonpFormatter(null,null)); Original code from: https://gist.github.com/jonathanhunt/2967547
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Net.Http.Formatting;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
@Injac
Injac / Set filter
Last active December 19, 2015 10:29
Shows how to extend a standard Telerik Report, to create filters at runtime using a new constructor.
/// <summary>
/// Initializes a new instance of the <see cref="YOURREPORT" /> class.
/// </summary>
/// <param name="YOURPARAMETER">The YOURPARAMETER.</param>
public YOURREPORTNAME(string YOURPARAM)
{
Filter userFilter = new Filter();
userFilter.Expression = "=Fields.YOURFIELD";
userFilter.Operator = FilterOperator.Equal; //CHOOSE YOUR OPERATOR HERE
userFilter.Value = String.Format("={0}", YOURPARAM);