Skip to content

Instantly share code, notes, and snippets.

@vnisor
vnisor / Linear Regression
Created Oct 19, 2021 — forked from xxsang/Linear Regression
Linear Regression
View Linear Regression
1. Simple linear regression
1. Assumes the dependence of response Y on predictors X1,…Xp is linear
2. Simple is good
3. residual: e = yi-yi_hat
4. residual sum of squares = e1^2+…en^2
5. optimisation problem to minimise total RSS, has closed form solution
6. A measure of precision -> how close the estimator is close to 0 (no relationship)
1. Standard error of the slope
2. var(e)/spread around the mean of X
3. SE of the intercept
@vnisor
vnisor / hwcdirect.md
Created Oct 17, 2019 — forked from sneal/hwcdirect.md
How to run Cloud Foundry hwc.exe directly
View hwcdirect.md

How to run hwc.exe directly without CloudFoundry

When web applications are pushed to CloudFoundry they are pushed out to one or more Windows cells and run inside the Hostable Web Core (HWC). HWC is the same component that IIS uses underneath to do the heavy lifting of serving ASP.NET applications. In Cloud Foundry the HWC is bootstrapped by the command line hwc.exe which works much like IISExpress.

Setup

We're going to serve the PCF .NET Environment Viewer app locally using the hwc.exe. These steps will guide you through all the prereqs to get that app working.

  1. Install the following Windows features: Hostable Web Core, ASP.NET 4.6, Websockets.
  2. Download or build the hwc executable. Place the hwc.exe in c:\containerizer.
View DisableMultipleQueuedItemsFilter.cs
public class DisableMultipleQueuedItemsFilter : JobFilterAttribute, IClientFilter, IServerFilter
{
private static readonly TimeSpan LockTimeout = TimeSpan.FromSeconds(5);
private static readonly TimeSpan FingerprintTimeout = TimeSpan.FromHours(1);
public void OnCreating(CreatingContext filterContext)
{
if (!AddFingerprintIfNotExists(filterContext.Connection, filterContext.Job))
{
filterContext.Canceled = true;
@vnisor
vnisor / gist:42ebcc196ab2d8675df46adfc191242c
Created Apr 19, 2017 — forked from CharlTruter/gist:2110398
How to change bindings on a site in IIS using C#
View gist:42ebcc196ab2d8675df46adfc191242c
void ChangeSiteBinding(string siteName, string oldBindingValue, string newBindingValue, string protocol)
{
using (ServerManager manager = new ServerManager())
{
// Find the site by name from IIS
Microsoft.Web.Administration.Site site = manager.Sites.Where(q => q.Name == siteName).FirstOrDefault();
if (site == null)
{
throw new Exception("The specified site name does not exist in IIS!");
}
@vnisor
vnisor / runner.js
Created Mar 31, 2017 — forked from phanan/runner.js
Record a webpage with PhantomJS and FFMpeg
View runner.js
// Run this from the commandline:
// phantomjs runner.js | ffmpeg -y -c:v png -f image2pipe -r 24 -t 10 -i - -c:v libx264 -pix_fmt yuv420p -movflags +faststart output.mp4
var page = require('webpage').create(),
address = 'http://s.codepen.io/phanan/fullembedgrid/YPLewm?type=embed&safe=true&_t=1424767252279',
duration = 3, // duration of the video, in seconds
framerate = 24, // number of frames per second. 24 is a good value.
counter = 0,
width = 500,
height = 500;
View ngrok-selfhosting-setup.md

Intro

The plan is to create a pair of executables (ngrok and ngrokd) that are connected with a self-signed SSL cert. Since the client and server executables are paired, you won't be able to use any other ngrok to connect to this ngrokd, and vice versa.

DNS

Add two DNS records: one for the base domain and one for the wildcard domain. For example, if your base domain is domain.com, you'll need a record for that and for *.domain.com.

Different Operating Systems

@vnisor
vnisor / elasticsearch-nest-geoquery-example.cs
Created Sep 19, 2016 — forked from crunchie84/elasticsearch-nest-geoquery-example.cs
Easy example of indexing geo-based domain objects to ElasticSearch via #nest
View elasticsearch-nest-geoquery-example.cs
using Nest;
using System;
using System.Globalization;
namespace elasticsearch_nest_geoindex_demo
{
public class Location
{
public string Name { get; set; }
@vnisor
vnisor / ngrok-selfhosting-setup.md
Created Sep 8, 2016 — forked from lyoshenka/ngrok-selfhosting-setup.md
How to setup Ngrok with a self-signed SSL cert
View ngrok-selfhosting-setup.md

Intro

The plan is to create a pair of executables (ngrok and ngrokd) that are connected with a self-signed SSL cert. Since the client and server executables are paired, you won't be able to use any other ngrok to connect to this ngrokd, and vice versa.

DNS

Add two DNS records: one for the base domain and one for the wildcard domain. For example, if your base domain is domain.com, you'll need a record for that and for *.domain.com.

Different Operating Systems

@vnisor
vnisor / postgres_table_row_count.sql
Created Apr 18, 2016
Row counts for all tables in a postgres db.
View postgres_table_row_count.sql
SELECT schemaname,relname,n_live_tup
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC;
View C# radix tree
public class Tree
{
/// <summary>
/// store the tree's root
/// </summary>
private Node _root;
/// <summary>
/// construct a new tree with it's root
/// </summary>