Skip to content

Instantly share code, notes, and snippets.

View reikoNeko's full-sized avatar

Rachel Rawlings reikoNeko

View GitHub Profile
def cryptogram(plaintext):
from random import shuffle
# create cryptogram cypher. You can't shuffle strings, so lists it is.
alpha = list('ABCDEFGHIJKLMNOPQRSTUVWXYZ')
beta = alpha[:]
shuffle(beta)
cmap = dict(zip(alpha,beta))
# Map the received string to a cryptogram. Note we're not cleaning any input.
cryptext = [ cmap[c] if c in alpha else c for c in plaintext.upper()]
return ''.join(cryptext)
def escape(seq):
jumps = 0
pos = 0
while True:
try:
offset = seq[pos]
seq[pos] +=1
pos += offset
jumps +=1
@reikoNeko
reikoNeko / gist:6a0600b3769d21a55cf2321f2a76651a
Created November 25, 2017 19:09
Flexible icinga DB performace data
def build_dict(seq, key):
return dict((d[key], dict(d)) for (_, d) in enumerate(seq))
i2stat = build_dict(raw["results"], 'name')
rate = {'IdoMysqlConnection': "idomysqlconnection_ido-mysql_queries_1min",
'IdoPgsqlConnection': "idomysqlconnection_ido-pgsql_queries_1min"}
print( set(i2stat.keys()) )
@reikoNeko
reikoNeko / dconf annoyances
Last active October 27, 2017 16:17
finding hard-to-find gnome3 settings and changing them
I see a few things in /usr/share/glib-2.0/schemas/org.gnome.desktop.wm.preferences.gschema.xml that aren't in Gnome-tweak-tool.
So I make a change and then do a find to see where the changes were made: .config/dconf/user -- which is parsed by dconf.
$ dconf dump / |grep -C1 raise
[org/gnome/desktop/wm/preferences]
auto-raise=true
That can be changed on the command line.
@reikoNeko
reikoNeko / echo9999.py
Last active September 25, 2017 16:33
A simple TCP listener that echoes what you send it. Works in Python 3 and 2. Based on the python2 listener in Black Hat Python.
#!/usr/env/python
from __future__ import print_function
import socket
import threading
bind_ip = "127.0.0.1"
bind_port = 9999
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind((bind_ip,bind_port))
@reikoNeko
reikoNeko / fizzbuzz
Last active September 14, 2017 00:59
A clear but not fully pythonic fizzbuzz implementation
def fizzbuzz(n):
for x in range(1,n+1):
result=''
if not x%3: result += ('fizz')
if not x%5: result += ('buzz')
yield result if result else str(x)
In [20]: foo = [(3,8), (5,3), (4,6), (1,5), (4,3), (4,7)]
In [21]: sorted(foo)
Out[21]: [(1, 5), (3, 8), (4, 3), (4, 6), (4, 7), (5, 3)]
In [22]: sorted(foo, key=lambda _: (-_[0],_[1]))
Out[22]: [(5, 3), (4, 3), (4, 6), (4, 7), (3, 8), (1, 5)]
In [23]: sorted(foo, key=lambda X: (-X[0], X[1]))
Out[23]: [(5, 3), (4, 3), (4, 6), (4, 7), (3, 8), (1, 5)]
I received the following comment from a web developer after I told him I wouldn't make his volatile files directory chmod 777 so Apache could write to it.
"777 tends to scare sys admins, so I understand."
Here's my response:
"Yes, it scares us and it should scare you.
"Think of your account like an apartment. If you set your permissions to 777, anyone who can get into the building (onto the server) can make changes: raid your fridge, steal your cat, replace your pillows, or plant evidence pointing to a crime you didn't commit. Even if they did none of those things, you can get skeeved out by the possiblility.
@reikoNeko
reikoNeko / php.log
Last active April 10, 2018 23:47
Self-healing PHP Code!
[~]$ cat <<EOF > suicide.php
> <?php
> unlink(__FILE__);
> ?>
> EOF
[~]$ php suicide.php
[~]$ cat suicide.php
cat: suicide.php: No such file or directory
[~]$
@reikoNeko
reikoNeko / fail2check.sh
Last active January 9, 2017 22:30
Quick command to get the status of every active jail on a server running fail2ban
#!/bin/env bash
CMD='sudo fail2ban-client status'; for J in `$CMD | awk -F':' '/Jail list/ {gsub(/,/,""); print $2}'` ; do $CMD $J ;done