Skip to content

Instantly share code, notes, and snippets.

View nycdotnet's full-sized avatar

Steve Ognibene nycdotnet

View GitHub Profile
@nycdotnet
nycdotnet / idea.md
Last active August 29, 2015 14:06
Idea for TypeScript constructor improvement

Problem Statement: In TypeScript 1.1, there are two basic ways to initialize complex properties with strong typing via a parameterized class constructor. Both have disadvantages. I will illustrate this with a simple example that uses Knockout, but this issue applies to any other JavaScript library that implements complex objects via initializer functions.

"Method 1" is to instantiate the properties outside of the constructor using a throw-away value, and then to set the desired value inside the constructor (see RightTriangle1 below). This method has the advantage of being rather simple to program/maintain because TypeScript automatically infers the property's type. However, this has the potential to cause ripple effects or performance issues at runtime because the code to instantiate each property is run at least twice.

class RightTriangle1 {
    public height = ko.observable(0);
    public width = ko.observable(0);
    public hypotenuse = ko.computed(() => {

consol

@nycdotnet
nycdotnet / output.text
Last active August 29, 2015 14:07
Double as binary
Testing 0
0-0-0-0-0-0-0-0-
After rehydrate: 0
Testing 1
0-0-0-0-0-0-240-63-
After rehydrate: 1
Testing -1
0-0-0-0-0-0-240-191-
After rehydrate: -1
Testing NaN
@nycdotnet
nycdotnet / QuickReload.vb
Last active August 29, 2015 14:15
Visual Studio Project Reload Macro
'===============================================================================
' This macro originally written by Sam Saffron, adapted for Visual Studio 2013
' by Steve Ognibene. Run in Visual Studio with a macro launcher such as the
' Visual Commander extension.
' Latest version will be here: https://gist.github.com/nycdotnet/947025d922fa2af87d03
' Original Stack Overflow thread: http://stackoverflow.com/questions/3783648/is-there-a-setting-in-vs-2010-that-will-allow-it-to-recover-open-files-after-a-p/28130299#28130299
' Also, thanks to Jeremy Jameson for code to write to VS Output window in a macro:
' http://blogs.msdn.com/b/jjameson/archive/2009/03/11/tracing-and-logging-from-visual-studio-macros.aspx
'===============================================================================
Option Explicit On
@nycdotnet
nycdotnet / Program.cs
Created May 4, 2015 16:36
C# Parameterized Events via Interfaces example
// INTERFACES
public interface ITicker
{
event Action<ITicker,ITimeOfTick> Tick;
}
public interface ITimeOfTick
{
DateTime Time { get; set; }
@nycdotnet
nycdotnet / Program.cs
Created June 1, 2015 13:43
Get releases info from GitHub API
using System.IO;
using System.Net;
namespace getReleaseInfo
{
class Program
{
static void Main(string[] args)
{
@nycdotnet
nycdotnet / exec.ts
Created June 1, 2015 16:50
Asynchronous Promise-based exec demo
import {Promise as Promise} from 'es6-promise';
module exec {
function doExec(shouldSucceed: boolean) : Promise<number> {
return new Promise((resolve, reject) => {
doSubExec(shouldSucceed)
.then((result) => {
resolve(result);
},(error) => {
@nycdotnet
nycdotnet / test.ts
Created August 20, 2015 15:18
http self-request
// demo of web server and client request. Lines 17 or 18 can be used and it works.
import http = require('http');
class Test {
request: http.ClientRequest;
private Connect() {
console.log("connecting");
this.request = http.request({
hostname: "localhost",
@nycdotnet
nycdotnet / Gruntfile.js
Created July 25, 2016 20:04
Run QUnit from command-line with Grunt
module.exports = function (grunt) {
grunt.initConfig({
qunit: {
default: {
options: {
urls: ["http://localhost:8000/tests/tests.html"]
}
}
},
connect: {
@nycdotnet
nycdotnet / UpdateJava.ps1
Last active September 13, 2017 13:20
Java update PowerShell script
# This script will uninstall anything like *Java* from Add/Remove Programs, Unblock and Install a new JDK,
# and set the JAVA_HOME environment variable for the new version.
#
# You have to set the $jdkInstallerPath first to the location where you got the JDK. Such as:
# $jdkInstallerPath = "C:\Users\MyAccount\Downloads\jdk-7u60-windows-x64.exe"
#
# WARNING: This will uninstall ANYTHING that says Java anywhere in the name!!! Use with caution!!!
#
# Note: This assumes that you are using the x64 JDK on 64-bit Windows. Not tested in other scenarios.
@nycdotnet
nycdotnet / code.cs
Created October 9, 2017 15:59
Get Constants On Type
/// <summary>
/// Enumerates constants on a type.
/// </summary>
public static IEnumerable<FieldInfo> GetConstantsOnType(Type TypeToReflect)
{
return TypeToReflect.GetFields().Where(f => f.IsStatic && f.IsLiteral);
}
/// <summary>
/// Enumerates constants on a type of a type.