Skip to content

Instantly share code, notes, and snippets.

View praveensewak's full-sized avatar
🎯
Focusing

Praveen praveensewak

🎯
Focusing
View GitHub Profile
@praveensewak
praveensewak / knockoutjs-helpers.js
Created May 20, 2013 04:32
A collection of KockoutJs helpers
var windowURL = window.URL || window.webkitURL;
ko.bindingHandlers.file = {
init: function (element, valueAccessor) {
$(element).change(function () {
var file = this.files[0];
if (ko.isObservable(valueAccessor())) {
valueAccessor()(file);
}
});
@praveensewak
praveensewak / Readme.md
Created June 5, 2013 06:29
jQuery Content Slider

//Usage $(element).contentslider({ direction: 'right', });

@praveensewak
praveensewak / util.js
Created April 16, 2014 23:42
JavasScript Helper Functions
//////////////////////////////////////////////////////////
// Checks whether a string contains a double byte character
// target = the string to be checked
//
// Return true if target contains a double byte char; false otherwise
//////////////////////////////////////////////////////////
function containsDoubleByte (target) {
var str = new String(target);
var oneByteMax = 0x007F;
@praveensewak
praveensewak / helper-functions.js
Created July 3, 2015 02:14
Essential JavaScript Functions
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
@praveensewak
praveensewak / GetClientIpWebApi.cs
Last active May 19, 2016 03:46
Get the IP address of the remote host in Web API
private string GetClientIp(HttpRequestMessage request)
{
if (request.Properties.ContainsKey("MS_HttpContext"))
{
return ((HttpContextWrapper)request.Properties["MS_HttpContext"]).Request.UserHostAddress;
}
if (request.Properties.ContainsKey(RemoteEndpointMessageProperty.Name))
{
RemoteEndpointMessageProperty prop;
@praveensewak
praveensewak / ThrottleRequestWebApi.cs
Created May 19, 2016 03:45
How to throttle requests in a Web Api?
[Route("api/dothis/{id}")]
[AcceptVerbs("POST")]
[Throttle(Name = "ApiThrottle", Message = "You must wait {n} seconds before accessing this url again.", Seconds = 5)]
[Authorize]
public HttpResponseMessage DoThis(int id)
{
// do something
}
public class ThrottleAttribute : ActionFilterAttribute
git log --pretty=oneline --since=1.day
@praveensewak
praveensewak / UsefulSqlQueries.sql
Created July 29, 2016 04:47
Useful Sql Queries
-- select maximum user connections for an db instance
SELECT maximum FROM sys.configurations WHERE name='user connections'
@praveensewak
praveensewak / ControllerTest.cs
Last active September 12, 2016 02:45
Unit Testing Helpers
namespace MvcApplication.Tests.Controllers
{
using System.Web.Mvc;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using MvcApplication.Controllers;
[TestClass]
public class AdminControllerTest
{
IUserService _userService;