Skip to content

Instantly share code, notes, and snippets.

@wilwang
wilwang / gist:3034508
Created July 2, 2012 17:40
Nano :: create db if not exists
var nano = require('nano')('http://localhost:5984');
var dbName = 'testdb';
var testDb = nano.use(dbName);
nano.db.list(function(error, databases) {
if (error)
return console.log('ERROR :: nano.db.list - %s', JSON.stringify(error));
if (databases.indexOf(dbName) < 0) {
nano.db.create(dbName, function(error, body, headers) {
@wilwang
wilwang / gist:5243112
Created March 26, 2013 04:19
HTML/Javascript :: example of animated scrolling
<!DOCTYPE html>
<html>
<head>
<title>Express</title>
<link rel="stylesheet" href="/assets/bootstrap/css/bootstrap.css">
<link rel="stylesheet" href="/stylesheets/style.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="/assets/bootstrap/js/bootstrap.js"></script>
</head>
<body>
@wilwang
wilwang / gist:5432217
Created April 22, 2013 03:15
javascript module pattern :: creates anonymous function that gets called immediately and returns the public interface
var myNamespace = (function() {
// private functions for your namespace
var getSelText = function() {
...
};
return {
run: function() {
var selectedText = getSelText();
alert (selectedText);
@wilwang
wilwang / gist:6241860
Created August 15, 2013 15:38
python script to look for a particular file (json), and parse, and print out what I want
import os
import json
def printJsonData(filename):
file = open(filename)
jsonString = file.read()
jsonString = jsonString.replace('\'', '"')
#print(jsonString)
jsonObject = json.loads(jsonString)
print(jsonObject['Namespace'] , '|', jsonObject['ProcPrefix'])
@wilwang
wilwang / js-performance
Created September 9, 2014 14:24
JS - Performant alternative to binding on heavy firing events
/*
Found on http://ejohn.org/blog/learning-from-twitter/
- neat way for performant JS when needing to bind on window scroll
*/
var outerPane = $details.find(".details-pane-outer"),
didScroll = false;
$(window).scroll(function() {
didScroll = true;
@wilwang
wilwang / gist:00e4ade121fabcd3864f
Created March 25, 2015 18:05
Get a table of Month Ends between two dates without using a LOOP
SET @StartDate = CONVERT(DATETIME, CONVERT(VARCHAR, MONTH(@StartDate)) + '/1/' + CONVERT(VARCHAR, YEAR(@StartDate)));
-- get a table of all of the month ends between @startDate and @endDate
CREATE TABLE #MonthEnds (
MonthEnd DATETIME
);
INSERT INTO #MonthEnds (MonthEnd)
SELECT TOP (DATEDIFF(MONTH, @StartDate, @EndDate)+1)
DATEADD(
DAY,
@wilwang
wilwang / StringPropertyTruncateSpecimenBuilder
Created August 4, 2015 21:42
autofixture specimen builder example to truncate strings
// lifted from http://stackoverflow.com/a/10130176/4040187
public class StringPropertyTruncateSpecimenBuilder<TEntity> : ISpecimenBuilder
{
private readonly int _length;
private readonly PropertyInfo _prop;
public StringPropertyTruncateSpecimenBuilder(Expression<Func<TEntity, string>> getter, int length)
{
_length = length;
_prop = (PropertyInfo)((MemberExpression)getter.Body).Member;
@wilwang
wilwang / UnityControllerFactory
Last active October 29, 2015 18:16
WebApi Controller Dependency Injection using Unity Container
// I'm not sure if this is the best or most correct way to do it, but it seems to work in my prototype.
// Basically, I want "dependency injection" for my controller, and after reading some tech blogs online,
// it seems like the best way to do this is to use IHttpControllerActivator to inject dependencies into
// your controller because you will have context of the request doing it this way as opposed to doing it
// via traditional dependency injection.
// this code in Global.asax.cs
public WebApiApplication()
{
this.container = new UnityContainer();
$targDir = "C:\dev\LMS-client-ADA";
Get-ChildItem $targDir -Filter *.pdf |
Foreach-Object {
$oldname = $_.FullName;
$newname = $_.FullName.Replace(" ", "_");
$newname = $newname -replace "[0-9]+\-[0-9]+\-[0-9]+_", "";
Rename-Item $oldname $newname;
@wilwang
wilwang / gist:4771a60f427fca97dd8dec3eabbae095
Created July 15, 2016 22:28
Powershell - Loop through sub directories and look for and rename file
$targDir = "C:\inetpub\websites\ADA*\";
$subDir = $(Get-ChildItem "$targDir");
foreach($sub in $subDir) {
$files = $(Get-Childitem $sub -Filter app_offline*.htm);
foreach($file in $files) {
$oldname = $file.FullName;