Skip to content

Instantly share code, notes, and snippets.

View HQarroum's full-sized avatar
:octocat:

Halim Qarroum HQarroum

:octocat:
View GitHub Profile
@HQarroum
HQarroum / initiate-ssm-connection.sh
Last active April 6, 2023 07:42
A Bash script to establish an SSM tunnel given an EC2 machine name, private DNS name, or identifier.
#!/bin/bash
set -e
if [ ! "$1" ]
then
echo "Expected a hostname of the instance as a parameter."
exit 1
fi
@HQarroum
HQarroum / ssh_config
Last active April 6, 2023 09:24
Add the ability for OpenSSH to integrate with Sessions Manager and support instance identifiers and instance names.
Host i-* mi-* aws-*
IdentityFile ~/.ssh/id_rsa
ProxyCommand ~/.ssh/initiate-ssm-connection.sh %h %p
@HQarroum
HQarroum / ssh_config
Last active April 5, 2023 21:26
A configuration integrating SSH with AWS SSM Sessions Manager.
Host i-* mi-*
ProxyCommand bash -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
@HQarroum
HQarroum / socat-adb-forwarding.sh
Last active May 7, 2024 17:05
Using socat to forward traffic from a network interface to the loopback address on which ADB is listening.
#!/bin/bash
set -e
# Installing required packages for the Android SDK
# and the emulator.
sudo apt update -y && \
DEBIAN_FRONTEND=noninteractive sudo apt install -y --no-install-recommends \
socat \
iproute2
@HQarroum
HQarroum / create-android-emulator.sh
Last active March 17, 2023 00:23
Creates a new Android emulator and launches it in a headless mode.
#!/bin/bash
set -e
# Environment variables defining the specific Android SDK
# to install.
export API_LEVEL="${API_LEVEL:-33}"
export IMG_TYPE="${IMG_TYPE:-google_apis}"
export ARCHITECTURE=x86_64
export ANDROID_SDK_ROOT="${ANDROID_SDK_ROOT:-/opt/android}"
@HQarroum
HQarroum / install-android-sdk.sh
Last active March 17, 2023 00:19
Installs the Android SDK, the platform tools and the emulator on Ubuntu.
#!/bin/bash
set -e
# Installing required packages for the Android SDK
# and the emulator.
sudo apt update -y && \
DEBIAN_FRONTEND=noninteractive sudo apt install -y --no-install-recommends \
unzip \
wget \
@HQarroum
HQarroum / mosquitto-pub-alpn.sh
Last active September 20, 2022 10:08
Example of using mosquitto_pub with ALPN extensions.
mosquitto_pub \
--cert path/to/certificate.pem.crt \
--key path/to/private/key.pem.key \
--cafile path/to/AmazonRootCA1.pem \
--host <id>-ats.iot.<region>.amazonaws.com \
--port 443 \
--tls-alpn "x-amzn-mqtt-ca" \
--topic "device/telemetry" \
--message "foo"
@HQarroum
HQarroum / phone-number-combinations.js
Last active July 9, 2022 19:03
Letter Combinations of a Phone Number
/**
* A fast solution to the problem of letter combinations of a phone number.
*
* Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.
* Return the answer in any order. A mapping of digits to letters (just like on the telephone buttons) is given.
* Note that 1 does not map to any letters.
*
* Example 1:
* Input: digits = "23"
* Output: ["ad","ae","af","bd","be","bf","cd","ce","cf"]
@HQarroum
HQarroum / pointer-arithmetics-challenge-implementation.c
Created August 3, 2021 22:04
pointer-arithmetics-challenge-implementation
#include <stdio.h>
/**
* A cross-platform and compiler independant implementation
* of offsetof.
*/
#define my_offsetof(ptr, member_name) \
(((size_t) (&(ptr)->member_name)) - ((size_t) ptr))
/**
@HQarroum
HQarroum / my_offsetof.c
Last active August 4, 2021 00:29
my_offsetof
#define my_offsetof(ptr, member_name) \
(((size_t) (&(ptr)->member_name)) - ((size_t) ptr))