Skip to content

Instantly share code, notes, and snippets.

View opennikish's full-sized avatar
:octocat:
Risen from the enterprise!

Nikita opennikish

:octocat:
Risen from the enterprise!
View GitHub Profile
@langseth
langseth / file_rename.py
Created February 10, 2012 05:18
simple example of kevent in python. Simply notes when a monitored file is deleted or renamed.
#!/usr/local/bin/python
import select
from select import kqueue, kevent
import os
import sys
filename = "access.log"
fd = os.open(filename,os.O_RDONLY)
kq = kqueue()
@jboner
jboner / latency.txt
Last active July 24, 2024 19:52
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers (~2012)
----------------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@brito
brito / API design
Created March 21, 2013 07:30
Joshua Bloch: Bumper-Sticker API Design
All programmers are API designers:
Good programs are modular, and intermodular boundaries define APIs. Good modules get reused.
APIs can be among your greatest assets or liabilities:
Good APIs create long-term customers; bad ones create long-term support nightmares.
Public APIs, like diamonds, are forever:
You have one chance to get it right so give it your best.
APIs should be easy to use and hard to misuse:
@ngenator
ngenator / bellmanford.py
Created August 7, 2013 21:11
Bellman-Ford algorithm in python
def bellman_ford(graph, source):
# Step 1: Prepare the distance and predecessor for each node
distance, predecessor = dict(), dict()
for node in graph:
distance[node], predecessor[node] = float('inf'), None
distance[source] = 0
# Step 2: Relax the edges
for _ in range(len(graph) - 1):
for node in graph:
@dergachev
dergachev / setuid-root-backdoor.md
Last active May 24, 2024 13:43
How to use setuid to install a root backdoor.

Why You Can't Un-Root a Compromised Machine

Let's say somebody temporarily got root access to your system, whether because you "temporarily" gave them sudo rights, they guessed your password, or any other way. Even if you can disable their original method of accessing root, there's an infinite number of dirty tricks they can use to easily get it back in the future.

While the obvious tricks are easy to spot, like adding an entry to /root/.ssh/authorized_keys, or creating a new user, potentially via running malware, or via a cron job. I recently came across a rather subtle one that doesn't require changing any code, but instead exploits a standard feature of Linux user permissions system called setuid to subtly allow them to execute a root shell from any user account from the system (including www-data, which you might not even know if compromised).

If the "setuid bit" (or flag, or permission mode) is set for executable, the operating system will run not as the cur

@itarato
itarato / encryption.java
Created September 28, 2014 18:59
Java AES CBC encryption example
package com.company;
import javax.crypto.Cipher;
import javax.crypto.Mac;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.security.MessageDigest;
import java.security.SecureRandom;
public class Main {
@robzwolf
robzwolf / Hollywood.md
Created April 18, 2021 17:37
Hollywood

How to Launch Hollywood on Windows, macOS or Linux

  1. Install Docker Desktop.
  2. Open a Terminal (Windows / Mac / Linux) and maximise it to the full size of your screen.
  3. $ docker run --rm -it bcbcarl/hollywood
  4. To exit: Try mashing Ctrl-D and Ctrl-C. If you get to a terminal you can type exit to close the container.

    If this fails, just quit your terminal. 😁