Skip to content

Instantly share code, notes, and snippets.

View grational's full-sized avatar

Giuseppe Ricupero grational

View GitHub Profile
@jackblk
jackblk / squid_proxy_tutorial.md
Last active April 24, 2025 14:43
Tutorial on how to setup a squid proxy with authentication.

Note

This tutorial is for Ubuntu & Squid3. Use AWS, Google cloud, Digital Ocean or any services with Ubuntu to follow this tutorial.

Install squid & update

sudo apt-get update
sudo apt-get install squid3
sudo apt-get install apache2-utils
@aasmith
aasmith / nested-json.sh
Created September 19, 2017 21:23
How to decode nested json with jq
# Typical use-case is decoding an AWS STS message. The DecodedMessage key contains escaped JSON.
jq '.DecodedMessage | fromjson | .' message.json
@vladfau
vladfau / post.groovy
Last active October 31, 2024 10:14
Sending POST + JSON Body + Auth - Libs in Java/Groovy (e.g. create tag on GitHub)
import groovy.json.JsonOutput
import java.io.BufferedWriter
import java.io.OutputStreamWriter
import java.net.URL
import java.util.Scanner
def url = new URL("https://${github}/api/v3/repos/${org}/${repo}/git/refs")
def urlConnection = url.openConnection()
urlConnection.setDoOutput(true)
@papapana
papapana / check.groovy
Created November 14, 2016 11:33
Check if key exists in map in Groovy
filter = [:]
key = 'example'
if (filter.containsKey(key)) {
// do if the key is contained
// e.g. filter[key] << 'hello_again'
} else {
// do if key is not contained
// e.g. filter[key] = ['hello']
}
@cboddy
cboddy / thunderbird_to_mutt.py
Created October 8, 2016 15:29
A script to parse a csv address-book export from thunderbird and create mutt-aliases for each contact.
"""parse a csv address-book export from thunderbird and create mutt-aliases for each contact"""
import csv
import collections
import argparse
Contact = collections.namedtuple("Contact", ["first", "last", "email"])
def line_to_contact(line):
"""return: Contact based on csv line"""
@abtrout
abtrout / redis-pipe.md
Last active August 11, 2023 03:29
Bash script to prepare Redis commands for mass insertion via `redis-cli --pipe`

Redis supports mass insert via redis-cli --pipe, but commands need to be written in redis protocol. For more details, check out the Redis mass insertion page. This script takes care of converting ordinary redis commands to redis protocol.

#!/usr/bin/env bash

while read CMD; do
  # each command begins with *{number arguments in command}\r\n
  XS=($CMD); printf "*${#XS[@]}\r\n"
  # for each argument, we append ${length}\r\n{argument}\r\n
 for X in $CMD; do printf "\$${#X}\r\n$X\r\n"; done
@kelvinn
kelvinn / cmd.sh
Created July 24, 2014 02:55
Example of using Apache Bench (ab) to POST JSON to an API
# post_loc.txt contains the json you want to post
# -p means to POST it
# -H adds an Auth header (could be Basic or Token)
# -T sets the Content-Type
# -c is concurrent clients
# -n is the number of requests to run in the test
ab -p post_loc.txt -T application/json -H 'Authorization: Token abcd1234' -c 10 -n 2000 http://example.com/api/v1/locations/
@xmzhao
xmzhao / gist:4144079
Created November 25, 2012 15:40
[hadoop] Passing parameters to Mappers and Reducer
http://www.thecloudavenue.com/2011/11/passing-parameters-to-mappers-and.html
There might be a requirement to pass additional parameters to the mapper and reducers, besides the the inputs which they process. Lets say we are interested in Matrix multiplication and there are multiple ways/algorithms of doing it. We could send an input parameter to the mapper and reducers, based on which the appropriate way/algorithm is picked. There are multiple ways of doing this
Setting the parameter:
1. Use the -D command line option to set the parameter while running the job.
2. Before launching the job using the old MR API
@andreyvit
andreyvit / tmux.md
Created June 13, 2012 03:41
tmux cheatsheet

tmux cheat sheet

(C-x means ctrl+x, M-x means alt+x)

Prefix key

The default prefix is C-b. If you (or your muscle memory) prefer C-a, you need to add this to ~/.tmux.conf:

remap prefix to Control + a