Skip to content

Instantly share code, notes, and snippets.

View khalidx's full-sized avatar
💭
Engineering for the ☁️

Khalid Zoabi khalidx

💭
Engineering for the ☁️
View GitHub Profile
@khalidx
khalidx / get-ip-address.sh
Created March 1, 2017 17:37
Ubuntu: Get only the IP address of a network interface
#!/bin/bash
# Syntax: ifconfig <interface-name> | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1
# Example: Get the IP address of the eth0 network interface
ifconfig eth0 | grep "inet addr" | cut -d ':' -f 2 | cut -d ' ' -f 1
@khalidx
khalidx / simple_http_server_cors.py
Last active September 21, 2023 02:24
Python SimpleHTTPServer with CORS, supporting both Python 2 and 3
#!/usr/bin/env python
# Usage: python simple_http_server_cors.py <port>
try:
# try to use Python 3
from http.server import HTTPServer, SimpleHTTPRequestHandler, test as test_orig
import sys
def test (*args):
test_orig(*args, port=int(sys.argv[1]) if len(sys.argv) > 1 else 8000)
@khalidx
khalidx / VERSIONING.md
Last active January 2, 2019 06:50
Basic Semantic Versioning

Basic Semantic Versioning

  • PATCH 0.0.x level changes for implementation level detail changes, such as small bug fixes
  • MINOR 0.x.0 level changes for any backwards compatible API changes, such as new functionality/features
  • MAJOR x.0.0 level changes for backwards incompatible API changes, such as changes that will break existing users code if they update

Further Reading

@khalidx
khalidx / README.md
Last active March 26, 2018 00:29
Flushing the DNS cache in Mac OS X

Run the following command in the terminal.

sudo killall -HUP mDNSResponder; sudo killall mDNSResponderHelper; sudo dscacheutil -flushcache

Make sure to also flush any other host name caches, like Chrome's.

Renaming a git branch

To rename a local git branch:

git branch -m <current_name> <new_name>

This is expecially useful when creating a feature under the wrong name when using git flow.

@khalidx
khalidx / SimpleStateMachine.java
Created January 10, 2019 20:14
A simple state machine implementation in Java using just an enum.
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public enum State {
Ready(Event.Deposit, Event.Quit),
Waiting(Event.Select, Event.Refund),
Dispensing(Event.Remove),
@khalidx
khalidx / node-red.md
Last active January 3, 2021 01:56
Start Node-RED using Docker (one-liner)

node-red

Node-RED is an awesome open-source tool for stream processing.

You can drag and drop "nodes" into your workflow, that can do things from processing a twitter stream to calling functions to sentiment analysis and automation.

All this is done with a visual drag and drop tool. No code to write (unless you want to)! Very powerful for simple to very advanced use cases.

Here's the command to run to launch Node-RED. Just make sure you have Docker installed.

@khalidx
khalidx / clear.js
Last active June 24, 2019 04:26
Clears the console (terminal), using Node.js
process.stdout.write('\x1b[2J');
process.stdout.write('\x1b[0f');
@khalidx
khalidx / README.md
Last active July 1, 2019 05:26
Publishing to NPM

Increments the version and creates a git tag, pushes the tags to the remote, then publishes to npm.

npm version patch
git push && git push --tags
npm publish
@khalidx
khalidx / dynamodb.ts
Created August 2, 2019 02:28
DynamoDb utility for usage in TypeScript with serverless-offline
import AWS from 'aws-sdk'
export default (process.env.IS_OFFLINE)
? new AWS.DynamoDB.DocumentClient({
region: 'localhost',
endpoint: 'http://localhost:8000',
accessKeyId: 'NONE',
secretAccessKey: 'NONE'
})
: new AWS.DynamoDB.DocumentClient()