Skip to content

Instantly share code, notes, and snippets.

@andreasbotsikas
andreasbotsikas / ImportGeoIpsToSql
Created December 11, 2014 15:17
Geo ip import to SQL Server
-- Download the country ip csv file from https://db-ip.com/db/ and save
-- the csv file in C:\temp\dbip-country.csv or change the script below
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[GeoIps]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[GeoIps](
[fromIp] [binary](4) NOT NULL,
[toIp] [binary](4) NOT NULL,
[fromIpDisplay] [varchar](15) NOT NULL,
[toIpDisplay] [varchar](15) NOT NULL,
@andreasbotsikas
andreasbotsikas / EncryptedSaml2SecurityTokenHandler
Created April 27, 2014 22:11
A Saml2SecurityTokenHandler that replaces the ServiceTokenResolver to enable token decryption
using System.Collections.Generic;
using System.IdentityModel.Selectors;
using System.IdentityModel.Tokens;
using System.Security.Cryptography.X509Certificates;
using System.Xml;
using Saml2SecurityTokenHandler = Microsoft.IdentityModel.Extensions.Saml2SecurityTokenHandler;
namespace Owin.Security.WsFederation
{
/// <summary>
@REM Create the hostednetwork named AbotNetwork and protect
@REM it using the 12345678 password
netsh wlan set hostednetwork ssid=AbotNetwork key=12345678
@REM Start the hostednetwork. Devices should be able to
@REM see the network after that and be able to obtain
@REM an ip on the 192.168.x.x range
netsh wlan start hostednetwork
@REM Stop the hostednetwork
@andreasbotsikas
andreasbotsikas / GrantExecute
Created March 23, 2014 19:36
Grant execute on schema (SQL Server)
GRANT EXECUTE ON DATABASE::DatabaseName TO SomeRoleOrUser;
GRANT EXECUTE ON SCHEMA::dbo TO SomeRoleOrUser;
@andreasbotsikas
andreasbotsikas / GitCleanUp
Created February 28, 2014 14:43
Clean up deleted objects in git
git -c gc.reflogExpire=0 -c gc.reflogExpireUnreachable=0 \
-c gc.rerereresolved=0 -c gc.rerereunresolved=0 \
-c gc.pruneExpire=now gc "$@"
# Copied from http://blogs.msdn.com/b/dimeby8/archive/2009/06/10/change-unidentified-network-from-public-to-work-in-windows-7.aspx
#
# Don't forget to run "set-executionpolicy remotesigned" to enable ps1 execution.
# Run this as admin
#
# Name: ChangeCategory.ps1
# Copyright: Microsoft 2009
# Revision: 1.0
#
# This script can be used to change the network category of
Restore database nameOfDbInTheBackupFile
FROM DISK = 'C:\dbFullBackup.bak'
with move 'mdf_file_name' to 'c:\db\mdf_file_name.mdf',
move 'ldf_file_name' to 'c:\db\ldf_file_name.LDF'
@andreasbotsikas
andreasbotsikas / odb2 driver configuration
Created November 4, 2013 16:48
odb2 driver configuration to record my odb2 sensor data in a file
{
"params" : {
"drivers" : [
{
"name" : "obd_driver",
"type" : "serial",
"filename" : "vehicle_recorder.js",
"interfaces" : [
{
"name" : "odbrecord",
@andreasbotsikas
andreasbotsikas / Custom ProfileBase to work with web applications
Created October 11, 2013 19:54
Working with Asp.Net in web applications
/// <summary>
/// To register, go to web.config and set
/// <profile enabled="true" inherits="Namespace.CustomProfile" >
/// </summary>
public class CustomProfile:ProfileBase
{
/// <summary>
/// Needs <anonymousIdentification enabled="true"/> in system.web in order to track anonymous
/// </summary>
/// <returns></returns>
using System;
using System.Runtime.InteropServices;
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool DeleteFile(string lpFileName);
// This code snippet is provided under the Microsoft Permissive License.
public static void Delete(string fileName) {
// call it with a file name prefixed by \\?\: