Skip to content

Instantly share code, notes, and snippets.

View vishvananda's full-sized avatar

Vish (Ishaya) Abrams vishvananda

  • Heroku
  • United States
View GitHub Profile
@vishvananda
vishvananda / python-is-slow.md
Last active March 21, 2023 07:33
Python is Slow

Introduction

A few weeks ago I was browsing Hacker News, and I noticed a post about a little online programming game called Colossal Cue Adventure. I was instantly hooked and three problems quickly fell to some hacked-together Python.

I was feeling pretty satisfied with myself until I noticed the little phrase at the bottom:

you can try your hand at the bonus level by typing bonus...
package main
import (
"fmt"
"math"
"math/bits"
"os"
"sync"
"time"
"unsafe"
import time
import math
import sys
import struct
data = """* 8 1 7 8 8 5 2 9 5 9 5
8 5 1 1 5 6 9 4 4 5 2 1
7 2 3 5 2 9 2 6 9 3 9 4
9 2 5 9 8 9 5 7 7 5 9 6
2 4 6 7 1 4 2 6 6 2 5 8
package main
import (
"fmt"
"math"
"os"
"time"
)
const (
@vishvananda
vishvananda / tunnel.sh
Created October 22, 2013 03:16
Script to set up an ipsec tunnel between two machines For Example: ./tunnel.sh 10.10.10.1 10.10.10.2 192.168.0.1 192.168.0.2 would set up an ipsec tunnel over 10.10.10.1 address using 192.168.0.1 as a virtual address passwordless sudo required for user on remote machine
#!/bin/bash
if [ "$4" == "" ]; then
echo "usage: $0 <local_ip> <remote_ip> <new_local_ip> <new_remote_ip>"
echo "creates an ipsec tunnel between two machines"
exit 1
fi
SRC="$1"; shift
DST="$1"; shift
diff --git a/nl/nl_linux.go b/nl/nl_linux.go
index ab76091..a49f675 100644
--- a/nl/nl_linux.go
+++ b/nl/nl_linux.go
@@ -27,7 +27,8 @@ const (
// tc rules or filters, or other more memory requiring data.
RECEIVE_BUFFER_SIZE = 65536
// Kernel netlink pid
- PidKernel uint32 = 0
+ PidKernel uint32 = 0
@vishvananda
vishvananda / docker_netns.sh
Last active January 8, 2022 18:21
Expose the netns of a docker container to the host.
#!/usr/bin/env bash
if [ "$1" == "" ]; then
echo "usage: $0 <docker_id>"
echo "Exposes the netns of a docker container to the host"
exit 1
fi
ppid=`docker inspect $1 | grep Pid | awk '{print $2 + 0}'`
if [ "$ppid" == "" ]; then
echo "lxc parent pid not found"
@vishvananda
vishvananda / strip-deb-key.sh
Created October 3, 2013 18:14
Strip the signing key from a debian package.
#!/usr/bin/env bash
if [ "$1" == "" ]; then
echo "Usage: $0 <deb-package>"
exit 1
fi
TARGET=$1
TMPDIR=`mktemp -d`
dpkg-deb -x $TARGET $TMPDIR
@vishvananda
vishvananda / getpass.sh
Last active January 8, 2022 18:21
Script for setting an encrypted password on boot
#!/usr/bin/env bash
SSH_KEYFILE=`tempfile`
SSL_KEYFILE=`tempfile`
if ! curl -s -f http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key > $SSH_KEYFILE; then
echo "Failed to get key"
fi
cat $SSH_KEYFILE
PASSWORD=`openssl rand -base64 48 | tr -d '/+' | cut -c1-16`
sudo usermod ubuntu -p `openssl passwd -1 $PASSWORD`
@vishvananda
vishvananda / translator.py
Created August 11, 2012 16:48
Translator to translate a python program into an equivalent program with a very limited set of characters
import os
with open('in.py') as infile:
data = infile.read()
def encode(char, sym):
return'+'.join([sym] * ord(char))
def write(outfile, wrap, boc, eoc, sep, sym='1'):
text = sep.join([boc + encode(char, sym) + eoc for char in data])