Skip to content

Instantly share code, notes, and snippets.

@alvarow
alvarow / node-http-server.js
Created August 17, 2016 20:38
Simple HTTP Server in node.js
var http = require('http');
//Lets define a port we want to listen to
const PORT=8080;
//We need a function which handles requests and send response
function handleRequest(request, response){
response.writeHead(200);
response.end('It Works!! Path Hit: ' + request.url);
console.log('It Works!! Path Hit: ' + request.url);
@alvarow
alvarow / bash-var-default-value.sh
Last active August 17, 2016 13:35
Bash default value environment variable that can be overridden
#!/bin/bash
: ${OVERRIDETHIS:="somedefault"}
echo ${OVERRIDETHIS}
@alvarow
alvarow / jenkins-rocket-status.py
Last active April 2, 2019 20:13
Send status of a given Jenkins build to a Rocket.chat webhook
#!/usr/bin/python2
# -*- coding: utf-8 -*-
import json
import sys
import urllib2
proxy = urllib2.ProxyHandler({ "http": "127.0.0.1:3128", "https": "127.0.0.1:3128" })
jenkinsUrl = "http://labs-jenkins/jenkins/job/"
rocketUrl ="https://your-rocket.chat/hooks/sasdfafsa"
@alvarow
alvarow / alvaro-redis.c
Last active July 7, 2016 21:56
Redist PING, SET, GET example. Requires hiredis library
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "hiredis.h"
// Shameless copy of example.c
// Depends on hiredis - download and make, drop this file on the hiredis folder and run
// gcc alvaro-redis.c libhiredis.a -o alvaro-redis -static
int main(int argc, char **argv) {
@alvarow
alvarow / alvd.c
Created June 21, 2016 02:53
Sample daemonizing code in C
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
void bye(int sig);
int main( int argc, char *argv[] )
@alvarow
alvarow / SimpleHTTPServer.py
Created June 21, 2016 02:37
Simple HTTPS server example written in python
# taken from http://www.piware.de/2011/01/creating-an-https-server-in-python/
# run as follows:
# python SimpleHTTPServer.py
# then in your browser, visit:
# https://localhost:8443
import BaseHTTPServer, SimpleHTTPServer
import ssl
httpd = BaseHTTPServer.HTTPServer(('localhost', 8443), SimpleHTTPServer.SimpleHTTPRequestHandler)
@alvarow
alvarow / auth.py
Last active June 16, 2016 14:24
auth.py tweaks for Trac's DirectoryAuthPlugin plugin - https://trac-hacks.org/wiki/DirectoryAuthPlugin
# -*- coding: utf-8 -*-
#
# Copyright (C) 2007 John Hampton <[email protected]>
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.
#
# Author: John Hampton <[email protected]>
# Extended: Branson Matheson <[email protected]>
@alvarow
alvarow / resize-tv.sh
Created May 28, 2016 01:14
Resize and crop images to fit on 1920x1080
#!/bin/bash
mkdir -p cropped
# parallel --eta convert {} -auto-orient -define jpeg:size=1920x1440 -resize 1920x1440 -crop 1920x1080+0+32 cropped/{} ::: *.JPG
for f in *.JPG
do
echo convert \"$f\" -auto-orient -define jpeg:size=1920x1440 -resize 1920x1440 -crop 1920x1080+0+32 cropped/\"$f\"
done | parallel --eta --will-cite
@alvarow
alvarow / my-pi-temp.sh
Last active May 26, 2016 18:21
RaspberryPi temperature
#!/bin/bash
# Script: my-pi-temp.sh
# Purpose: Display the ARM CPU and GPU temperature of Raspberry Pi 2/3
# based of: Vivek Gite <www.cyberciti.biz> under GPL v2.x+
# -------------------------------------------------------
cpu=$((`cat /sys/class/thermal/thermal_zone0/temp|cut -c1-2`)).$((`cat /sys/class/thermal/thermal_zone0/temp|cut -c3-4`))
echo "$(date) @ $(hostname)"
echo "-------------------------------------------"
echo "GPU => $(/opt/vc/bin/vcgencmd measure_temp)"
echo "CPU => ${cpu}'C"
@alvarow
alvarow / exifttool-cheat.sh
Last active April 28, 2016 18:24
exiftool scratch pad
# Adjust GPS tag on files in a folder
exiftool -GPSLongitudeRef=W -GPSLongitude="73.87538" -GPSLatitudeRef=N -GPSLatitude=40.850581 -ext cr2 jpg jpeg .
# Move files into Year/Month folders in a given folder
exiftool "-Directory<DateTimeOriginal" -d "%Y/%m" DIR
# Rename files in a folder using Year Month Day Hour Minute Second format
exiftool '-FileName<CreateDate' -d %Y%m%d_%H%M%S%%-c.%%e DIR
exiftool -AllDates+=1 *.JPG
# Adjust file modification date
exiftool "-DateTimeOriginal>FileModifyDate" *.JPG
# Copy tags from another file