Skip to content

Instantly share code, notes, and snippets.

View sp9usb's full-sized avatar

Kamil Myśliwiec sp9usb

View GitHub Profile
@sp9usb
sp9usb / Cascade drop all tables.sql
Last active September 21, 2016 06:58
PostgreSQL block code
DO $$
DECLARE
all_tables CURSOR FOR SELECT table_name FROM information_schema.tables WHERE table_schema = 'public';
BEGIN
FOR table_record IN all_tables LOOP
EXECUTE 'DROP TABLE ' || table_record.table_name || ' CASCADE';
END LOOP;
END $$;
@sp9usb
sp9usb / gist:e19856ea108a0d1e138c
Created November 18, 2014 12:25
MSBuild Project Transformate
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterCompile" Condition="exists('app.$(Configuration).config')">
<!-- Generate transformed app config in the intermediate directory -->
<TransformXml Source="app.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="app.$(Configuration).config" />
<!-- Force build process to use the transformed configuration file from now on. -->
<ItemGroup>
<AppConfigWithTargetPath Remove="app.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
@sp9usb
sp9usb / gist:6cf2ebe31ab6a6630da4
Created November 26, 2014 10:48
Create list of unnamed type
void foobar(Type t)
{
var listType = typeof(List<>);
var constructedListType = listType.MakeGenericType(t);
var instance = Activator.CreateInstance(constructedListType);
}
var result = _repository.SystemGet(spec)
.GroupBy(g => g.SensorGuid, record => record, (guid, records) => records.OrderByDescending(r => r.Timestamp).FirstOrDefault())
.ToList();
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cassandra;
using Cassandra.Data;
using Cassandra.Data.Linq;
using metrics.Core;
using metrics.Reporting;
using System.Diagnostics;
netsh interface portproxy add v4tov4 listenport=4422 listenaddress=192.168.1.111 connectport=80 connectaddress=192.168.0.33
#!/bin/bash
# THESE ARE NOTES, NOT TESTED AS SCRIPT!
# We need the following to get and run teamcity agent
sudo apt-get install openjdk-7-jre-headless
sudo apt-get install unzip #For unzipping buildAgent.zip
# For compiling Simple.Web
sudo apt-get install ruby1.9.1
@sp9usb
sp9usb / gist:5d240d44d7e266ae844f
Last active August 29, 2015 14:21
Linux Init.d install script
# VirtualBox installer shell routines
#
# Copyright (C) 2007-2012 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# you can redistribute it and/or modify it under the terms of the GNU
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
@sp9usb
sp9usb / Room.cs
Last active January 26, 2016 07:03
[EntityFramework] Many to many
public class Room
{
public Guid Id { get; set; }
public string Title { get; set; }
public virtual User Manager { get; set; }
public virtual ICollection<User> Members { get; set; }
}
@sp9usb
sp9usb / ArgumentExceptions.cs
Created December 22, 2017 12:01
Generic exceptions concept
using System;
namespace Sm.Exceptions
{
public abstract class ArgumentExceptions : Exception
{
protected ArgumentExceptions() { }
protected ArgumentExceptions(string message) : base(message) { }
}