Skip to content

Instantly share code, notes, and snippets.

View omidnasri's full-sized avatar
🏢
PTFCH

Omid Nasri omidnasri

🏢
PTFCH
View GitHub Profile
@omidnasri
omidnasri / SqliteContext.cs
Last active September 19, 2015 13:43 — forked from flaub/SqliteContext.cs
SQLite EF 6 Database Initializer
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Data.SQLite;
using System.Linq;
namespace SQliteEF6
{
class SqliteContext : DbContext
@omidnasri
omidnasri / cookies.js
Created November 28, 2015 10:39 — forked from ajaxray/cookies.js
Small JavaScript class to help create, read and delete cookie.
/**
* Cookies - A small class to manipulate cookies from javascript
*
* Compressed version: https://gist.github.com/4147384
*
* @see www.quirksmode.org/js/cookies.html
* @author Anis uddin Ahmad <anisniit@gmail.com>
*/
window.Cookies = {
@omidnasri
omidnasri / readme.md
Created December 19, 2015 08:29 — forked from benpriebe/readme.md
Making web.config appSettings available via JavaScript (ASP.NET MVC)

Making web.config appSettings available via JavaScript (ASP.NET MVC)

You may wish to expose server side configuration via JavaScript. For example, you may have a different base url for your REST api per environment (dev,test,uat,prod) which your JavaScript AJAX calls need to consider.

Typically, you would push the configuration data down via an html5 data- attribute, a hidden input field or via explicit assignment to a JavaScript global. You usually end up doing this for every item you wish to expose. However, using a custom MVC ActionFilterAttribute and a Server-to-JSON serialization technique you can easily expose your web.config appSettings for controller actions.

NOTE: Exposing the entire appSettings configuration section may expose your application to security risks.

How

@omidnasri
omidnasri / StringEncoder.cs
Created February 13, 2016 08:30 — forked from xixilive/StringEncoder.cs
Base32 string encoder developing with C#
using System;
using System.Collections.Generic;
using System.Text;
namespace Mickey.Utils
{
/// <summary>
/// 字符串编码/解码
/// </summary>
public static class StringEncoder
{
@omidnasri
omidnasri / cookies.min.js
Created March 11, 2016 13:08 — forked from ajaxray/cookies.min.js
Small JavaScript class to help create, read and delete cookie. [compressed]
/**
* Cookies - [compressed] A small class to manipulate cookies from javascript
* Uncompressed version: https://gist.github.com/gists/4139367
*/
window.Cookies={set:function(e,t,n,r){if(n){var i=new Date;i.setTime(i.getTime()+n*24*60*60*1e3);var s="; expires="+i.toGMTString()}else var s="";var o=r||"/";document.cookie=e+"="+t+s+"; path="+o},get:function(e){var t=e+"=";var n=document.cookie.split(";");for(var r=0;r<n.length;r++){var i=n[r];while(i.charAt(0)==" ")i=i.substring(1,i.length);if(i.indexOf(t)==0)return i.substring(t.length,i.length)}return null},"delete":function(e){this.set(e,"",-1)}}
@omidnasri
omidnasri / index.js
Created March 13, 2016 08:56 — forked from stinoga/index.js
Replacing query string parameter values.
// Update the appropriate href query string parameter
function paramReplace(name, string, value) {
// Find the param with regex
// Grab the first character in the returned string (should be ? or &)
// Replace our href string with our new value, passing on the name and delimeter
var re = new RegExp("[\\?&]" + name + "=([^&#]*)"),
delimeter = re.exec(string)[0].charAt(0),
newString = string.replace(re, delimeter + name + "=" + value);
return newString;
@omidnasri
omidnasri / Program.cs
Created May 27, 2016 18:43 — forked from ardalis/Program.cs
A StructureMap Example using a Console Application
using System;
using System.Linq;
using StructureMap;
namespace ConsoleApplication1
{
/// <summary>
/// See http://stackoverflow.com/questions/6777671/setting-up-structure-map-in-a-c-sharp-console-application
/// Updated for SM 4: http://ardalis.com/using-structuremap-4-in-a-console-app
/// </summary>
@omidnasri
omidnasri / jQuery.antiforgerytoken.js
Created August 26, 2016 06:20 — forked from scottrippey/jQuery.antiforgerytoken.js
ASP.NET MVC AntiForgeryToken + AJAX = jQuery to the rescue
// Setup CSRF safety for AJAX:
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
if (options.type.toUpperCase() === "POST") {
// We need to add the verificationToken to all POSTs
var token = $("input[name^=__RequestVerificationToken]").first();
if (!token.length) return;
var tokenName = token.attr("name");
@omidnasri
omidnasri / convert-image-to-base64.js
Created September 4, 2016 17:05 — forked from HereChen/convert-image-to-base64.js
convert image to base64
/**
* version1: convert online image
* @param {String} url
* @param {Function} callback
* @param {String} [outputFormat='image/png']
* @author HaNdTriX
* @example
convertImgToBase64('http://goo.gl/AOxHAL', function(base64Img){
console.log('IMAGE:',base64Img);
})
@omidnasri
omidnasri / jquery-api.md
Created September 23, 2016 08:53 — forked from azat-co/jquery-api.md
The list of most commonly used jQuery API functions

Here is the list of most commonly used jQuery API functions:

  • find(): Selects elements based on the provided selector string
  • hide(): Hides an element if it was visible
  • show(): Shows an element if it was hidden
  • html(): Gets or sets an inner HTML of an element
  • append() Injects an element into the DOM after the selected element
  • prepend() Injects an element into the DOM before the selected element
  • on(): Attaches an event listener to an element
  • off() Detaches an event listener from an element