Skip to content

Instantly share code, notes, and snippets.

View carstengehling's full-sized avatar

Carsten Gehling carstengehling

View GitHub Profile
@carstengehling
carstengehling / snippets.ps1
Created August 24, 2023 18:21
Powershell snippets
###############################################################################
# Search/replace text in files recursively
$utf8 = New-Object System.Text.UTF8Encoding $True
Get-ChildItem . *.xaml -recurse |
Foreach-Object {
$content = [System.IO.File]::ReadAllText($_.FullName)
if ($content.Contains('{DynamicResource '))
{
@carstengehling
carstengehling / OrderStateMachine.cs
Created August 2, 2023 10:43
MassTransit SagaStateMachine boilerplate from documentation
public record CreateOrder(Guid CorrelationId) : CorrelatedBy<Guid>;
public record ProcessOrder(Guid OrderId, Guid ProcessingId);
public record OrderProcessed(Guid OrderId, Guid ProcessingId);
public record OrderCancelled(Guid OrderId, string Reason);
public class ProcessOrderConsumer : IConsumer<ProcessOrder>
{
@carstengehling
carstengehling / windows-install.ps1
Last active May 22, 2024 10:42
Powershell script to install vital apps and behaviours on a fresh Windows 11 install
# Remove Windows 11 crapware
winget uninstall "Cortana" --silent --accept-source-agreements
winget uninstall "Disney+" --silent --accept-source-agreements
winget uninstall "Mail and Calendar" --silent --accept-source-agreements
winget uninstall "Microsoft News" --silent --accept-source-agreements
winget uninstall "Microsoft OneDrive" --silent --accept-source-agreements
winget uninstall "Microsoft Tips" --silent --accept-source-agreements
winget uninstall "MSN Weather" --silent --accept-source-agreements
winget uninstall "Movies & TV" --silent --accept-source-agreements
winget uninstall "Office" --silent --accept-source-agreements
public class SqlQueue : IQueue
{
private SqlConnection _connection;
public SqlQueue(SqlConnection connection)
{
if (connection == null) throw new ArgumentNullException("connection");
_connection = connection;
}
var s1 = ""
+ "<OTA_HotelAvailNotifRQ MessageContentCode=\"1\" >"
+ "<AvailStatusMessages HotelCode=\"60737\">"
+ "<AvailStatusMessage BookingThreshold=\"-10\">";
var s = @"<OTA_HotelAvailNotifRQ MessageContentCode=""1"" >
<AvailStatusMessages HotelCode=""60737"">
<AvailStatusMessage BookingThreshold=""-10"">
";
@carstengehling
carstengehling / BackgroundWorker.cs
Created September 13, 2017 05:10
Let only on process do work
public class BackgroundWorker
{
private Mutex mutex = new Mutex(true, "some-unique-id");
public void Run()
{
bool handleAquired = false;
try
{
@carstengehling
carstengehling / app_state.rb
Created September 9, 2013 12:47
Simple application-wide flag setter/getter, using ActiveRecord as backend. Would anyone be interested in this as a fully working gem?
class AppState < ActiveRecord::Base
attr_accessible :key, :value
validates :key, presence: true
serialize :value
def self.get_value(key, default_value = nil)
as = AppState.find_by_key(key)
return default_value if as.blank?
@carstengehling
carstengehling / xmldiff
Created February 1, 2013 20:12
Using xmllint to make XML files ready for diff'ing
#!/bin/sh
FILE1=/tmp/`basename $1`
FILE2=/tmp/`basename $2`
xmllint --c14n $1 > $FILE1
xmllint --c14n $2 > $FILE2
diff $FILE1 $FILE2
Loading development environment (Rails 3.2.2)
1.8.7 :001 > require 'odf/spreadsheet'
=> true
1.8.7 :002 > ODF::Spreadsheet.file("my-spreadsheet.ods") do |spreadsheet|
1.8.7 :003 > spreadsheet.table 'My first table from Ruby' do |table|
1.8.7 :004 > table.row {|row| row.cell 'Hello, rODF world!' }
1.8.7 :005?> end
1.8.7 :006?> end
NoMethodError: undefined method `encode' for Builder::XChar:Module
from /home/carsten/.rvm/gems/ruby-1.8.7-p358@misstoro_partner/gems/rodf-0.2.1/lib/odf/span.rb:30:in `xml'
douglas:~# vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
1 1 664 122084 300 2910664 0 0 0 2 1 1 3 1 76 21
0 1 664 121532 300 2911028 0 0 476 10 85 302 1 0 35 65
0 1 664 121192 300 2911408 0 0 320 0 42 118 0 0 51 49
0 1 664 120196 300 2912456 0 0 1008 312 153 336 0 0 49 51
0 1 664 119728 300 2912924 0 0 456 0 59 173 0 0 51 49
0 1 664 119056 300 2913440 0 0 608 0 80 194 0 0 49 51
0 1 664 117736 300 2914824 0 0 1384 9 176 395 0 0 50 50