Skip to content

Instantly share code, notes, and snippets.

@WorthyD
WorthyD / QueryString.js
Last active August 29, 2015 14:01
JavaScript Get Query String
var QueryString =(function(w){
return {
GetVariable: function (variable) {
var query = '',
vars = [],
i = 0,
pair = '';
if (!window.location || !window.location.search) {
//No query string to search.
var Cookies = (function (d, w) {
return {
Set: function (cookieName, cookieValue, daysExperation) {
var expires = '',
xpDate = new Date();
if (daysExperation) {
xpDate.setTime(xpDate.getTime() + (daysExperation * 24 * 60 * 60 * 1000));
expires = '; expires=' + xpDate.toUTCString();
}
d.cookie = cookieName + '=' + cookieValue + expires + '; path=/';
//Should fix any console log issues.
if (!window.console) {
console = {
log: function () { },
time : function () { },
timeEnd : function () { }
}
};
@WorthyD
WorthyD / 0_reuse_code.js
Created June 2, 2014 02:10
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
var RandomNumbers =(function(w){
return {
//l = low
//h = high
GetInt: function (l, h) {
return l + w.Math.floor(Math.random() * (h - l));
},
GetFloat: function (l, h) {
return l + w.Math.random() * (h - l);
}
var canTouch = 'ontouchstart' in window;
var startEvent = canTouch ? 'touchstart' : 'mousedown';
var moveEvent = canTouch ? 'touchmove' : 'mousemove';
var endEvent = canTouch ? 'touchend' : 'mouseup';
@WorthyD
WorthyD / KonamiCode.js
Created June 3, 2014 17:50
Konami Code Snippet
if ( window.addEventListener ) {
var kkeys = [], konami = "38,38,40,40,37,39,37,39,66,65";
window.addEventListener("keydown", function(e){
kkeys.push( e.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ){
//Logic
}
}, true);
}
@WorthyD
WorthyD / GetCached.cs
Created July 8, 2014 15:17
Generic GetCached Query
/// <summary>
/// Generic caching call
/// </summary>
/// <typeparam name="TEntity">Class to map query to</typeparam>
/// <param name="query">Query to be executed</param>
/// <param name="CacheKey">Unique key used for reference on server</param>
/// <param name="CacheDurationSeconds">Duration for data to remain cached</param>
/// <returns> List of queried object</returns>
public IList<TEntity> GetCached<TEntity>(IQueryable<TEntity> query, string CacheKey, int CacheDurationSeconds) {
IList<TEntity> list = System.Web.HttpRuntime.Cache[CacheKey] as IList<TEntity>;
@WorthyD
WorthyD / _vimrc
Last active August 20, 2019 14:29
set nocompatible " be iMproved, required
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=$VIMRUNTIME/../vimfiles/bundle/Vundle.vim/
let path='$VIMRUNTIME/../vimfiles/bundle'
call vundle#begin(path)
"call vundle#begin()
" let Vundle manage Vundle, required
" Vim color file
" Maintainer: Marco Peereboom <slash@peereboom.us>
" Last Change: August 19, 2004
" Licence: Public Domain
" Try to emulate standard colors so that gvim == vim
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif