Skip to content

Instantly share code, notes, and snippets.

@colegatron
colegatron / getviewport.php
Last active August 29, 2015 13:56
Google Maps Api Viewport : From a latitude and longitude and a radius get two latlong pairs to be used as a viewport (for example)
<?php
/**
* User: Ivan Gonzalez / Colegatron
* Date: 18/07/13
* Time: 16:14
*/
header('Content-Type: application/json');
$lat = $_GET["lat"];
@colegatron
colegatron / gist:10723614
Created April 15, 2014 11:11
IIS6 regexp log
((?# date)\d{4}\-\d{2}\-\d{2}\s+)((?# time)\d{2}\:\d{2}\:\d{2}\s+)((?# s-sitename).+?\s+)((?# s-computername).+?\s+)((?# s-ip)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s+)((?# cs-method).+?\s+)((?# cs-uri-stem).+?\s+)((?# cs-uri-query).+?\s+)((?# s-port)\d{1,3}\s+)((?# cs-username).+?\s+)((?# c-ip)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\s+)((?# cs-version)(HTTP\/\d\.\d)|\-\s+)((?# csUser-Agent).+?\s+)((?# csCookie).+?\s+)((?# csReferer).+)((?# cs-host).+?\s+)((?# sc-status)\d{1,3}\s+)((?# sc-substatus)\d{1,3}\s+)((?# sc-win32-status)\d+\s+)((?# sc-bytes)\d+\s+)((?# cs-bytes)\d+\s+)((?# time-taken)\d+)
Credits to http://weblogs.asp.net/ktegels/archive/2005/01/31/364272.aspx
-- Only procced with deletion if the there are at least @MINIMUM_IN_DB records for the last @NDAYS
DECLARE @NDAYS int = 3 -- Number of days to preserve
DECLARE @MININUM_IN_TABLE int = 2100000 -- Records needed in the DB for the last @NDAYS to proceed to deletion
DECLARE @TODELETE int = 1000 -- Delete un chunks of @TODELETE records
DECLARE @TOTALRECS int = ( select count(*) from intermediate where datediff(day, insertdate,getdate()) < @NDAYS )
IF ( @TOTALRECS >= @MININUM_IN_TABLE )
BEGIN
@colegatron
colegatron / Recursively find folders named "xml_contents" and delete them
Last active August 29, 2015 14:18
Find folder named "Content" and delete them recursively
$folderToRemove = "Contents"
$rootFolder = "e:\import_logs"
$folders = Get-ChildItem -Recurse -Force $rootFolder -ErrorAction SilentlyContinue | Where-Object { ($_.PSIsContainer -eq $true) -and ( $_.Name -like $folderToRemove) }
foreach ($folder in $folders) {
write-host "Removing " $folder.FullName
remove-item -re -fo $folder.FullName
}
# install 7-zip, curl and vim
# (Windows 2012 comes with .NET 4.5 out-of-the-box)
# Then use the EC2 tools to create a new AMI from the result, and you have a system
# that will execute user-data as a PowerShell script after the instance fires up!
# This has been tested on Windows 2012 64bits AMIs provided by Amazon (eu-west-1 ami-a1867dd6)
#
# Inject this as user-data of a Windows 2012 AMI, like this (edit the adminPassword to your needs):
#
# <powershell>
# Set-ExecutionPolicy Unrestricted
@colegatron
colegatron / AWS EC2 dinamically add 2nd ENI to instance
Created December 9, 2015 16:23
AWS EC2 dinamically add 2nd ENI to instance (and only a 2nd
INSTID=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
echo "Getting instance info..."
aws ec2 describe-instances --instance-id $INSTID --region eu-west-1 | jq .Reservations > /tmp/descinstance.json
if [ $( cat /tmp/descinstance.json | jq '.[].Instances[0].NetworkInterfaces | length' ) -gt 1 ]; then
echo "[WARNING] Instance already has more than one ENI"
else
echo "Creating ENI..."
aws ec2 create-network-interface --subnet-id subnet-14416563 --description "Nic2 SaltMaster DevTest Network [$INSTID]" --groups sg-28dc214d --region eu-west-1 > /tmp/create-eni.json
echo "Getting ENI id..."
NICID=$(cat /tmp/create-eni.json | jq .NetworkInterface.NetworkInterfaceId | sed "s/\"//g")
@colegatron
colegatron / getviewport.php
Created July 18, 2013 14:52
From a latitude and longitude and a radius get two latlong pairs to be used as a viewport (for example)
<?php
/**
* User: Ivan Gonzalez / Colegatron
* Date: 18/07/13
* Time: 16:14
*/
header('Content-Type: application/json');
$lat = $_GET["lat"];
@colegatron
colegatron / README-saltstack-postfix-forwarder
Last active May 12, 2016 09:48
saltstack postfix formula as forwarder (for root emails)
This is an update of the Russel's state to use it basically as mail forwarder in auto scaled environments.
The tipycal problem is that if you get notification emails from "webserver@mydomain.com" in an environment where you really have 5 or 6 webservers for the same application, it is difficult to track back the issue to the right server.
I have solved it renaming the server and the headers:
All the emails sent from the server for <myhostname>.domain.com will renamed to <senderuser>@<myhostname-my-ipv4>.domain.com.
Also adds a header replacement to avoid problems with Office365 mail servers, which rejects to send emails with different names on the hostname and the email headers
Original job: http://russell.ballestrini.net/postfix-salt-state-formula/
@colegatron
colegatron / Move Ubuntu to the new machine
Created July 21, 2016 13:57
Move Ubuntu to the new machine
Whenever is possible, try to do not install anything on your desktop.
Use virtualbox.
Better, use Docker.
Don't feel bad. I have lots of shit installed in my desktop too.
------
On source machine: