Skip to content

Instantly share code, notes, and snippets.

@leandrosilva
leandrosilva / Client.cs
Created October 31, 2010 02:54
Asynchronous Client/Server Socket Example with C# (from MSDN library)
// Asynchronous Client Socket Example
// http://msdn.microsoft.com/en-us/library/bew39x2a.aspx
using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;
// State object for receiving data from remote device.
@leandrosilva
leandrosilva / Makefile
Created March 11, 2011 15:58
Makefile to compile, run, and test Erlang applications
APP_NAME := my_awesome_app
all: compile
compile: clear
@cp src/$(APP_NAME).app ebin/
@erlc -pa ebin/ -o ebin/ src/*.erl
compile_test: compile
@erlc -pa ebin/ -o ebin/ test/*.erl
@leandrosilva
leandrosilva / README
Last active March 17, 2023 19:05
Parsing Syslog files with Python and PyParsing
$ python xlog.py sample.log
{'appname': 'test.app', 'timestamp': '2012-09-06 15:19:32', 'hostname': 'codezone.local', 'pid': '68898', 'priority': '132', 'message': 'bla bla bla warn'}
{'appname': 'test.app', 'timestamp': '2012-09-06 15:19:32', 'hostname': 'codezone.local', 'pid': '68902', 'priority': '131', 'message': 'bla bla bla error'}
{'appname': 'Dock', 'timestamp': '2012-09-06 15:19:32', 'hostname': 'codezone.local', 'pid': '154', 'priority': '11', 'message': 'CGSReleaseWindowList: called with 5 invalid window(s)'}
{'appname': 'WindowServer', 'timestamp': '2012-09-06 15:19:32', 'hostname': 'codezone.local', 'pid': '79', 'priority': '11', 'message': 'CGXSetWindowListAlpha: Invalid window 0'}
$ python xlog.py sample.log | grep test.app
{'priority': '132', 'timestamp': '2020-03-04 12:42:40', 'hostname': 'codezone.local', 'appname': 'test.app', 'pid': '68898', 'message': 'bla bla bla warn'}
@leandrosilva
leandrosilva / fts.sql
Created October 6, 2022 20:47
Full Text Search "sort of" with prefix, infix, fuzzy, and similarity on the Almighty Postgres
SELECT
pos,
sim,
p.*
FROM
produtos AS p,
NULLIF(POSITION('seme' IN LOWER(COALESCE(p.gtin, '') || ' ' || COALESCE(p.descricao, ''))), 0) AS pos,
NULLIF(SIMILARITY(LOWER(COALESCE(p.gtin, '') || ' ' || COALESCE(p.descricao, '')), 'seme'), 0) AS sim
WHERE
(LOWER(COALESCE(p.gtin, '') || ' ' || COALESCE(p.descricao, ''))) LIKE 'seme%'
@leandrosilva
leandrosilva / BinaryPrintHelper.cs
Created October 24, 2017 15:06
Print to a network printer over LPR/LPD protocol
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@leandrosilva
leandrosilva / parallel_for.cs
Last active November 8, 2021 21:20
Source code for the article "Tudo ao mesmo tempo agora com C#" originally published at https://medium.com/pricefy-labs
private static void ParallelFor()
{
var numberOfIterations = 1000;
var min = 0;
var max = 100_000_000;
var random = new Random();
var breakIndex = random.Next(1, numberOfIterations);
@leandrosilva
leandrosilva / README
Created November 24, 2010 00:46
Using F# to parse command line options with Mono.Options
Sample code on how to parse command line options with Mono.Options.
Mono.Options can be downloaded and compiled from:
https://github.com/mono/mono/tree/master/mcs/class/Mono.Options/Mono.Options
@leandrosilva
leandrosilva / xsp4-stop.sh
Created November 5, 2012 18:45
Kill xsp4 if it's running
kill `ps aux | grep xsp4.exe | grep -v grep | awk '{print $2}'`
@leandrosilva
leandrosilva / compile.rb
Created July 16, 2010 18:53
A little sugar to use Mono C# 4.0 compiler
#!/usr/bin/env ruby
#
# A little sugar to use Mono C# 4.0 compiler.
#
# Author: Leandro Silva
# . leandrodoze@gmail.com
# . http://leandrosilva.com.br
# . @codezone
#
@leandrosilva
leandrosilva / color_reference_code.txt
Created July 30, 2010 19:29
Output colorization in Ruby
Code Effect
0 Turn off all attributes
1 Set bright mode
4 Set underline mode
5 Set blink mode
7 Exchange foreground and background colors
8 Hide text (foreground color would be the same as background)
30 Black text
31 Red text
32 Green text