Skip to content

Instantly share code, notes, and snippets.

@antoni
antoni / Makefile
Created August 26, 2016 15:14
A Super-Simple Makefile for Medium-Sized C/C++ Projects (https://spin.atomicobject.com/2016/08/26/makefile-c-projects/)
TARGET_EXEC ?= a.out
BUILD_DIR ?= ./build
SRC_DIRS ?= ./src
SRCS := $(shell find $(SRC_DIRS) -name *.cpp -or -name *.c -or -name *.s)
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIRS) -type d)
def _parse_boot_device_list(boot_device_list):
"""
Returns boot devices order specified by current_assigned_sequence field
(a list with names of the devices)
"""
boot_order = []
for _, devices in boot_device_list.items():
for boot_device in devices:
id_parts = boot_device.id.split("#")
@antoni
antoni / Local MITM SSH proxy
Created July 27, 2016 12:13
Local MITM SSH proxy
sudo iptables -t nat -D OUTPUT -p tcp -m owner ! --uid-owner root --dport 443 -j REDIRECT --to-port 8080
This document describes about installation and configuration of IPMI simulator.
We need: qemu-kvm, OpenIPMI, OpenIPMI-tools
1) Install the qemu-kvm. We need the qemu, which have the IPMI pacthes.
Use the source https://github.com/cminyard/qemu/tree/stable-2.2-ipmi
./configure, make and make install
2) Download the OpenIPMI libraries, from http://sourceforge.net/projects/openipmi/
Follow the process documented in lanserv/README.vm
./configure --prefix=/opt/openipmi/usr --sysconfdir=/opt/openipmi/etc \
--with-perlinstall=/opt/openipmi/usr/lib/perl \
@antoni
antoni / mysql_secure.sh
Created May 14, 2016 22:07 — forked from Mins/mysql_secure.sh
Automating mysql_secure_installation
#!/bin/bash
aptitude -y install expect
// Not required in actual script
MYSQL_ROOT_PASSWORD=abcd1234
SECURE_MYSQL=$(expect -c "
set timeout 10
@antoni
antoni / gist:83edb611014b8255a2708f0d3ec5a21a
Last active April 25, 2016 09:09
Terminal escape sequences
# Source: https://m.reddit.com/r/netsec/comments/4fi3hn/detecting_the_use_of_curl_bash_server_side/
$ cat > evil.sh <<EOF
echo rm -rf /home; FOO=^M echo "nothing fishy here!"
EOF
$ cat evil.sh
echo "nothing fishy here!"
$ source evil.sh
rm -rf /home
nothing fishy here!
@antoni
antoni / FileDownload.java
Created April 13, 2016 13:51
Download file using Java NIO
URL website = new URL(FILE_URL);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(TMP_FILE_NAME);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
@antoni
antoni / linux_snippets.sh
Created March 17, 2016 19:02
Linux snippets
# Fix:
# E: This installation run will require temporarily removing the essential package sysvinit-utils:amd64 due to a Conflicts/Pre-Depends loop. This is often bad, but if you really want to do it, activate the APT::Force-LoopBreak option.
apt-get update && apt-get dist-upgrade -o APT::Force-LoopBreak=1
@antoni
antoni / random_in_range.cc
Created February 28, 2016 21:32
Generate random number in range (C++)
#include <random>
int main(int argc, char *argv[]) {
#ifdef APPROACH1 // C++11
std::random_device rd; // used once to initialise (seed) engine
// random-number engine (Mersenne-Twister in this case)
std::mt19937 rng(rd());
std::uniform_int_distribution<int> uni(min, max); // guaranteed unbiased
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->