Skip to content

Instantly share code, notes, and snippets.

@rgl
rgl / gist:2366299
Created April 12, 2012 10:22
Async HTTP requests using Async IO and Task Parallel Library (TPL)
private static HealthState GetHealthState()
{
// addresses is-a List<string>
var addresses = GetServers().SelectMany(s => s.IPs.Where(ip => ip.Type == "Backend").Select(ip => ip.Value));
var totalAddresses = addresses.Count();
var cancellationTokenSource = new CancellationTokenSource();
@rgl
rgl / gist:2550634
Last active August 17, 2021 04:48
Example PoC on how to configure WINRM and execute a remote powershell command on Windows
// see PowerShell Remoting on Python at https://www.bloggingforlogging.com/2018/08/14/powershell-remoting-on-python/
// see https://github.com/jborean93/pypsrp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
// NB you should add reference to C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\System.Management.Automation.dll (this is installed by the Windows SDK).
@rgl
rgl / list-network-interfaces.go
Last active April 30, 2017 13:07
Example on how to list network interfaces and their state and addresses
package main
import "net"
import "fmt"
import "reflect"
func main() {
interfaces, error := net.Interfaces()
if error != nil {
fmt.Printf("ERROR getting interfaces %s\n", error)
@rgl
rgl / tidy_xml_lint.py
Last active December 19, 2015 02:39
this is a sublime text 2 (and 3 too) plugin to tidy and format xml (using xmllint). you need xmllint installed on your system. I've used the msys-libxml2 package from MinGW MSYS (install with mingw-get install msys-libxml2). See http://blog.ruilopes.com/post/2143557964/sane-shell-environment-on-windows to known how I've set it up. you might need…
#
# Copy this file into the user package directory (eg. to C:\Users\Rui Lopes\AppData\Roaming\Sublime Text 3\Packages\User).
# NB you can go into this directory by opening the Preferences | Browse Packages... menu.
#
# Add a shortcut to run this command by using sublime Preferences | Key Bindings - User:
#
# [
# {
# "keys": ["ctrl+shift+x"],
# "command": "tidy_xml_lint"
@rgl
rgl / http-server-status-et-al.js
Created July 4, 2013 14:49
Q&D http server for trying out client features. at the moment, status codes and response delay.
var http = require("http");
var url = require("url");
var pathHandlers = {
"/": function(request, response, uri) {
response.writeHead(200, {"Content-Type": "text/html"});
response.write("<ul>\n");
response.write("<li><a href='status?code=404'>status - 404</a></li>\n");
response.write("<li><a href='status?code=500'>status - 500</a></li>\n");
response.write("<li><a href='sleep?duration=5000'>sleep - 5s</a></li>\n");
@rgl
rgl / gist:7468598
Created November 14, 2013 15:19
A simple file system crawler that erases old temporary files and empty directories.
using log4net;
using System;
using System.IO;
using System.Timers;
using System.Web.Hosting;
namespace Util
{
public class AssetHelperJanitor
{
@rgl
rgl / format_json.py
Last active December 30, 2015 22:39
this is a sublime text 3 plugin to format selected (or all file) JSON text.
#
# Copy this file into the user package directory (eg. to C:\Users\Rui Lopes\AppData\Roaming\Sublime Text 3\Packages\User).
# NB you can go into this directory by opening the Preferences | Browse Packages... menu.
#
# Add a shortcut to run this command by using sublime Preferences | Key Bindings - User:
#
# [
# {
# "keys": ["ctrl+shift+j"],
# "command": "format_json"
@rgl
rgl / gimp_xcf_list_layers.py
Created January 1, 2014 22:08
List the layers of a GIMP xcf file. This also exports the visible layers into a png file.
# This lists the layers of a GIMP xcf file. This also exports the visible layers into a png file.
#
# Execute the commands:
#
# curl -O https://bitbucket.org/rgl/make_dmg/downloads/background.xcf
# gimp -idf --batch-interpreter=python-fu-eval -b - -b 'pdb.gimp_quit(0)' < gimp_xcf_list_layers.py
#
# See http://www.gimp.org/docs/python/
# See http://gimpbook.com/scripting/
#
@rgl
rgl / PurgePop3Account.cs
Created March 4, 2014 11:34
Purge a POP3 account
using OpenPop.Pop3; // from http://www.nuget.org/packages/OpenPop.NET/
using System;
namespace PurgePop3Account
{
class Program
{
static void Main(string[] args)
{
// use the pop3s scheme for SSL connection (recommended).
@rgl
rgl / CheckJce.java
Last active August 29, 2015 14:04
try to use a non-limited key size to see whether the Java Cryptography Extension (JCE) Unlimited Strength is correctly installed. without it the maximum key size are limited to 128-bit.
package CheckJce;
import java.security.NoSuchAlgorithmException;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
public class CheckJce {
public static void main(String[] args) throws Exception {
String message = "Java Cryptography Extension (JCE) Unlimited Strength is correctly installed!";