Skip to content

Instantly share code, notes, and snippets.

View menacestudio's full-sized avatar

Dennis Rongo menacestudio

View GitHub Profile
@menacestudio
menacestudio / dynamic_cursor_sample.sql
Created November 13, 2014 03:11
Dynamic and cursor sample
CREATE TABLE #codes ( code VARCHAR(10))
INSERT INTO #codes( code )
SELECT distinct c.someCode FROM dbo.tbl_Sample c WITH(NOLOCK) WHERE c.isDeleted=0 AND NOT ISNULL(c.parts,'')='C'
AND c.someDate1 >= @anotherDate AND c.someDate1 <= @endDate
AND c.providerID IN (SELECT userId from #tmpTable)
ORDER by c.someCode
-- Temp table for output
CREATE TABLE #tbl_Sample2 (userid INT, employee VARCHAR(200), type VARCHAR(150), results INT null)
@menacestudio
menacestudio / user_defined_type.sql
Last active August 29, 2015 14:09
Using a user defined type in SQL.
ALTER PROCEDURE [dbo].[usp_SaveSearch]
@userId INT,
@searchId INT = 0,
@searchName VARCHAR(250) = '',
@searchCriteria dbo.TvpItem readonly
AS
BEGIN
SET NOCOUNT ON;
IF (@searchID = 0)
@menacestudio
menacestudio / index.cshtml
Last active August 29, 2015 14:07
MVC app sample
@model ViewModels.IProjectViewModel
@{
var projects = Model.GetProjects(Model.ProjectModel.Id);
ViewBag.Title = "All Projects View";
}
@section scripts {
<script>
$(function () {
@menacestudio
menacestudio / 0_reuse_code.js
Created August 16, 2014 07:33
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
@menacestudio
menacestudio / upload.cs
Created June 12, 2014 22:32
File upload
HttpFileCollection uploadFiles = Request.Files;
// Build HTML listing the files received.
string summary = "<p>Files Uploaded:</p><ol>";
// Loop over the uploaded files and save to disk.
int i;
for (i = 0; i < uploadFiles.Count; i++)
{
HttpPostedFile postedFile = uploadFiles[i];
@menacestudio
menacestudio / angular.cshtml
Last active October 19, 2016 22:48
Quick AngularJS CRUD
@section scripts {
<script>
var app = window.app = {};
app.userTypes = @Html.Raw(Json.Encode(Model.GetUserTypes()));
</script>
<script src="~/Scripts/angular.min.js"></script>
<script src="~/Scripts/angular-resource.min.js"></script>
<script src="~/Scripts/underscore.min.js"></script>
<script src="~/Scripts/angular/main.js"></script>
// Original idea: http://stackoverflow.com/questions/9565889/get-the-ip-address-of-the-remote-host
using System.Net.Http;
using System.ServiceModel.Channels;
using System.Web;
namespace CrowSoftware.Api
{
public static class HttpRequestMessageHelper
{
@menacestudio
menacestudio / md_to_html.py
Created March 13, 2013 00:42
Converts a Markdown file to HTML.
# Author: Dennis Rongo
# Date: 03.12.2013
# Description: Thie script converts a Markdown (*.md) file to HTML within the same directory.
# This requires Pandoc (http://johnmacfarlane.net/pandoc/) to do the conversion.
import sys
import getopt
import subprocess
def process(arg):
@menacestudio
menacestudio / backbone_ajax1.js
Created March 12, 2013 22:30
Backbone: Override AJAX methods
/** Global override to make all AJAX calls as POST type */
Backbone.ajax = function() {
var args = Array.prototype.slice.call(arguments, 0);
return Backbone.$.ajax.apply(Backbone.$, _.extend(args, {type: 'POST'}));
};
/** Manual override per call */
Collection.fetch({data: {id: 34}, type: 'POST'});
@menacestudio
menacestudio / option1.js
Last active December 14, 2015 19:49
Backbone: Only persist a Model with valid attributes.
var President = Backbone.Model.extend({});
var m = new President({first: 'Abraham', last: 'Lincoln', age: 90, registered: true});
m.set({first: null});
/** Loop through each property and unset if invalid. Also check if property if boolean type. */
_.each(m.toJSON(), function(val, col){
if (typeof val !=='boolean' && !val) {
m.unset(col);
}