Skip to content

Instantly share code, notes, and snippets.

$ time ab -n 100 -c 1 'http://localhost:9200/logs/_search?q=x'
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software:
Server Hostname: localhost
@rgl
rgl / ppa_stats.py
Created April 27, 2011 07:57
outputs the download count of a PPA
# this outputs the download count of a PPA
#
# See https://api.launchpad.net/+apidoc/devel.html#binary_package_publishing_history
# See https://help.launchpad.net/API/launchpadlib
from launchpadlib.launchpad import Launchpad
cachedir = '/home/rgl/.launchpadlib/cache/'
launchpad = Launchpad.login_anonymously('just testing', 'production', cachedir)
@rgl
rgl / gist:1070433
Created July 7, 2011 20:10
Recreate (drop and create) an SQL Server Database.
//
// Recreate (drop and create) an SQL Server Database.
//
// NB: This will place the database in single mode (also rolling back current transactions).
//
// usage: RecreateDatabase(@"Data Source=.\SQLServer; Initial catalog = ESB_Store_Development; Integrated Security=True;");
private static void RecreateSqlServerDatabase(string connectionString)
{
const string databaseNameRegexPattern = @"(;\s*Initial Catalog\s*=\s*)([^;]+)\s*";
@rgl
rgl / gist:2028339
Created March 13, 2012 11:45
Example on how to read application settings configuration
// NB you should probably use SixPack instead...
// On App.config:
/*
<configuration>
<configSections>
<section name="snmpPoller" type="Tracing.Service.Snmp.SnmpPollerSettings,Tracing.Service.Snmp"/>
</configSections>
<snmpPoller pollingInterval="4000" timeout="3000">
<variables>
@rgl
rgl / gist:2158698
Created March 22, 2012 14:41
Serialize xsd:anyType on a client proxy
/*
When you have a XML schema with a xsd:anyType element, eg:
<complexType name="Example">
<sequence>
<element name="DateTime" type="dateTime" minOccurs="1" maxOccurs="1" />
<element name="Value" type="string" minOccurs="1" maxOccurs="1" />
<element name="Details" type="anyType" minOccurs="0" maxOccurs="1" />
</sequence>
</complexType>
@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 / 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"