Skip to content

Instantly share code, notes, and snippets.

@odedlaz
odedlaz / safe_readlines.py
Created December 22, 2021 18:21
str.readlines that yields the lines. instead of reading a file into memory and splitting all lines, use this function to read line-by-line
def safe_readlines(f, block_size=32, max_file_size=1024 * 1024):
read = 0
buf = ""
read_block = functools.partial(f.read, 32)
for block in map(bytes.decode, iter(read_block, b'')):
assert read + block_size <= max_file_size, "manifest file is too big"
read += len(block)
first, *rest = block.splitlines()
@odedlaz
odedlaz / vssh.fish
Last active March 26, 2021 23:50
vssh
#!/usr/bin/env fish
# add the following line to ~/.config/fish/completions in order to add hostname completion to the script
# complete -x -c vssh -d "Remote" -a "(__fish_complete_user_at_hosts)"
function get_gateway --argument addr
route -n get -net $addr | awk '/gateway/ { print $2 }'
end
function get_global_protect_interface_ipaddr_from_config
@odedlaz
odedlaz / get-clang-6.0.sh
Last active April 24, 2019 13:53
Install Clang 6.0
#!/usr/bin/env bash
set -euo pipefail
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
code_name=$(lsb_release -c | awk '{ print $2}')

Keybase proof

I hereby claim:

  • I am odedlaz on github.
  • I am odedlaz (https://keybase.io/odedlaz) on keybase.
  • I have a public key whose fingerprint is 5017 D338 3F64 1ADF 43C6 EF9D 515C 0ACE 5D29 39A2

To claim this, I am signing this object:

@odedlaz
odedlaz / weather-forecast.py
Last active December 27, 2017 16:06
weather-geolocation-script
#!/usr/bin/env python
# sh is mighty! have a look: https://github.com/amoffat/sh
from sh import awk, iwlist
import requests
import sys
import os
__dir__ = os.path.dirname(os.path.realpath(__file__))
#!/usr/bin/env python
import pika
import time
import sys
import json
name = 'hello ' + sys.argv[1]
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
@odedlaz
odedlaz / nginx-docker-compose.yml
Created July 27, 2017 12:48
A simple docker-compose file for nginx
version: '3'
services:
web:
image: nginx
network_mode: "host"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
ports:
- 80:80
@odedlaz
odedlaz / nginx.conf
Created July 27, 2017 12:47
A simple nginx reverse proxy configuration
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@odedlaz
odedlaz / move.md
Last active June 22, 2017 08:03
Goodbye Gartner, Hello Cybereason

TL;DR: I'm leaving Gartner Innovation Center and joining Cybereason. Why? I found myself in a comfort zone.

The blog post is split into four parts:

  • Past: A brief history of Senexx and how Gartner Innovation Center was formed.
  • Present: What Gartner Innovation Center is doing now
  • The decision to move
  • Future: My thoughts on what's going to happen next

Past

@odedlaz
odedlaz / bitsrepr.c
Created May 4, 2017 14:58
Represent an integer in binary format
#include <stdio.h>
#include <stdlib.h>
void dtob(unsigned int word, char* text) {
for (int bit = 31; bit >= 0; bit--) {
int shift = word >> bit;
printf("%d", shift & 1);
}
printf(" (%s: %d)\n", text, word);
}