Skip to content

Instantly share code, notes, and snippets.

@alexnavis
alexnavis / blog_python_async.py
Last active February 22, 2020 15:56
Blog: Python Async
import random
def magic_pot(start=1, end=1000):
while True:
stop = (yield random.randint(start, end))
if stop is True:
print("magicpot stopped")
break
@alexnavis
alexnavis / SNMPv3AES.ex
Last active May 31, 2017 07:58
SNMP v3 AES not working
:snmp.start()
:crypto.start()
:snmpm.register_user('v3_default_user', :snmpm_user_default, nil, [])
# http://snmpsim.sourceforge.net/public-snmp-simulator.html
# snmpget -v 3 -u "usr-md5-aes" -a MD5 -x AES -X "privkey1" -A "authkey1" -l authPriv demo.snmplabs.com 1.3.6.1.2.1.1.1.0
engine_id = "80004fb805636c6f75644dab22cc" |> Base.decode16!(case: :mixed) |> :binary.bin_to_list
user_name = 'usr-md5-aes'
@alexnavis
alexnavis / SNMPv3.ex
Last active May 23, 2017 09:44
SNMP Elixir / Erlang v3
:snmpm.start()
:snmpm.register_user('v3_default_user', :snmpm_user_default, nil, [])
# Public SNMP simulator - http://snmpsim.sourceforge.net/public-snmp-simulator.html
engine_id = "80004fb805636c6f75644dab22cc" |> Base.decode16!(case: :mixed) |> :binary.bin_to_list
user_name = 'usr-md5-none'
password = 'authkey1'
auth_key = :snmp.passwd2localized_key(:md5, password, engine_id)
ip_address = {104,236,166,95}
@alexnavis
alexnavis / https_login.py
Last active July 11, 2018 13:17
Python HTTP/HTTPS code to login
import urllib, urllib2, cookielib
URL = 'http://dummyurl.com'
cj = cookielib.CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
login_data = urllib.urlencode({ "password":"12345678", "email":"xyz@gmail.com" })
resp = opener.open(URL, login_data)
print resp.headers
print resp.read()
@alexnavis
alexnavis / redis_pump.rb
Last active January 9, 2017 16:22
Redis Data Pump
#!/usr/bin/ruby
require 'redis'
require 'securerandom'
require 'benchmark'
HOST = ENV['HOST'] || 'localhost'
PORT = ENV['PORT'] || '60812'
DB = 0
LIST_SIZE_PER_PROCESS=300000
NO_OF_PROCESS=5
@alexnavis
alexnavis / redis_debug.rb
Last active January 7, 2022 16:02
Redis Big Keys, Dump Debug Info with Humanized Size Information to Export CSV
# Intention to dump from live redis. Use rdb-tools to dump from a file.
# To know the usage run: >> ruby redis_debug.rb
require 'redis' # needs redis gem to work
require 'csv'
class RedisDebug
DEFAULT_OPTS = { redis: {host: 'localhost', port: '6379', db: 0, timeout: 100},
batch_size: 2000,