Skip to content

Instantly share code, notes, and snippets.

View reikoNeko's full-sized avatar

Rachel Rawlings reikoNeko

View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@reikoNeko
reikoNeko / AoC4-1.ipynb
Last active December 8, 2016 19:04
Create default dict to find valid keys for Advent of Code 4-1, part 1
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# In[17]:
keypad=[[1,2,3],[4,5,6],[7,8,9]]
def kp_move(position,ditherings):
r,c = position
#print(ditherings[:3],ditherings[-3:])
for char in ditherings:
if 'U' == char:
r = max(0, r-1)
elif 'D' == char:
@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
@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
[~]$
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.
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)]
@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)
@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 / 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.