Skip to content

Instantly share code, notes, and snippets.

@nsonnad
nsonnad / tsv2csv.py
Created November 22, 2013 11:38
Python script for converting tsv to csv
import sys
import csv
tabin = csv.reader(sys.stdin, dialect=csv.excel_tab)
commaout = csv.writer(sys.stdout, dialect=csv.excel)
for row in tabin:
commaout.writerow(row)
@danrigsby
danrigsby / packer-ami-id
Last active December 14, 2023 15:07
Get AMI ID from a packer build
packer build packer.json 2>&1 | sudo tee output.txt
tail -2 output.txt | head -2 | awk 'match($0, /ami-.*/) { print substr($0, RSTART, RLENGTH) }' > sudo ami.txt
@idlethreat
idlethreat / gelf-listener.py
Last active May 23, 2022 11:26
Gelf Log Listener in Python
#!/usr/bin/env python
############### // gelfListener 0.2 // ###############
#
# Listens on UDP 12201 for Gelf messages
# Extracts the event data and writes the message to disk
# updated to handle both zlib (nxlog) and gzip (graylog server) compressed events
# not perfect, but works okay
#
# Bugs:
@davidfowl
davidfowl / Example1.cs
Last active March 28, 2024 20:36
How .NET Standard relates to .NET Platforms
namespace Analogy
{
/// <summary>
/// This example shows that a library that needs access to target .NET Standard 1.3
/// can only access APIs available in that .NET Standard. Even though similar the APIs exist on .NET
/// Framework 4.5, it implements a version of .NET Standard that isn't compatible with the library.
/// </summary>INetCoreApp10
class Example1
{
public void Net45Application(INetFramework45 platform)
@stevenringo
stevenringo / deploy_stack.sh
Created September 11, 2017 00:13
Create/update/delete cloudformation stacks with events tailing
set -o pipefail
_exit_error() {
message=$1
code=$2
echo "$message" >&2
exit $code
}
_exit_ok() {
@amilos
amilos / FolderController.cs
Created October 20, 2017 17:00
Use of wildcard and regex based route constraints in asp.net
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using System.IO;
namespace Asseco.Content.Controllers
{
[Route("api/v1/content/")]
public class FolderController : Controller
{
private JsonResult GetFileByPath(string repo, string folder, string file)
@rraval
rraval / postgres-collation.md
Last active December 6, 2023 16:25
PostgreSQL collation is a massive footgun

This is a slightly stripped down version from our internal bug tracker. The point of posting this publicly is part FYI, part peer review. I'm hoping someone can look at this, disagree, and tell me all the downsides of using the C locale or point out things I've misunderstood. The Recommendations section in particular is contextualized by our database serving a SaaS product for users from many different locales, thus making locale a render level concern. YMMV, caveat emptor, etc.


Collation defines the character ordering for textual data. For Postgres, https://www.postgresql.org/docs/current/static/locale.html:

The locale settings influence the following SQL features:

  • Sort order in queries using ORDER BY or the standard comparison operators on textual data
  • The upper, lower, and initcap functions
@andyraddatz
andyraddatz / ASCIIStringExtensions.cs
Last active December 12, 2023 08:55
C# String extension method to fold diacritics to ASCII characters
// IMPORTANT
using System.Text;
// This gist was created thanks to this comment from Alexander on StackOverflow:
// https://stackoverflow.com/questions/249087/how-do-i-remove-diacritics-accents-from-a-string-in-net#comment86833005_34272324
// This is a derivative work. The logic of this function comes from a switch statement found inside the
// Lucene.Net library. The documentation of the conversion of characters is quite impressive
// (thank you @NightOwl888 and @synhershko !!!):
// https://github.com/apache/lucenenet/blob/master/src/Lucene.Net.Analysis.Common/Analysis/Miscellaneous/ASCIIFoldingFilter.cs