Skip to content

Instantly share code, notes, and snippets.

@ntrrgc
ntrrgc / request_cert.sh
Created December 29, 2014 18:56
Script to request and install renewed StartSSL certificates
#!/bin/bash
set -eu
if [ "$#" -ne 1 ]; then
echo "Usage: $0 domain.example.com"
echo
echo "Generates a private key and a default CSR which you can send to" \
"your CA. It prompts later for the certificate and stores it in a" \
"reasonable place."
echo "Tested only with StartSSL."
exit 1
@ntrrgc
ntrrgc / tls-ugly-hack.js
Created January 8, 2015 02:59
Patch node's TLS module to skip certificate name check
// This is a modified version of node's built-in tls.js patched not to check
// the server hostname against its certificate.
//
// node 0.10 does not support this in a clean way.
// This will be allowed in node 0.12 setting a checkServerIdentity function
// in the HTTPS agent config.
function checkServerIdentity(host, cert) {
return true;
}
@ntrrgc
ntrrgc / open-pdf.html
Created May 11, 2015 21:48
Bookmarklet to open embedded PDF in iPad
<html>
<head>
<title>Open PDF</title>
</head>
<body>
javascript:location.href=document.querySelector('object[type="application/pdf"]').getAttribute('data')
</body>
</html>
@ntrrgc
ntrrgc / keywords.py
Created May 17, 2015 19:00
Rank keyword density
import sys
import nltk
import nltk.tokenize.regexp
import nltk.stem.snowball
import nltk.corpus
import requests
import lxml.html
lang = 'spanish'
def get_text():
@ntrrgc
ntrrgc / codec.py
Created May 27, 2015 22:59
Digole OLED monochrome video codec (accepts animated GIF or static images)
#encoding: utf-8
import sys
import time
import PIL.Image
def marshal_image(image):
data = image.convert('1')
w, h = data.size
out = bytearray()
@ntrrgc
ntrrgc / palette-image
Created June 4, 2015 17:30
Convert colon separated hex color strings into palette images and vice versa
#!/usr/bin/python
import sys
from PIL import Image, ImageDraw, ImageColor
from argparse import ArgumentParser
cell_w = cell_h = 40
def color_to_hex(color):
return '#' + ''.join('%02x' % x for x in color)
@ntrrgc
ntrrgc / make_cert.sh
Created August 4, 2015 22:19
Script to request and install new SSL certificates without moving files by hand
#!/bin/bash
set -eu
if [ "$#" -ne 1 ]; then
echo "Usage: $0 domain.example.com"
echo
echo "Generates a private key and a default CSR which you can send to" \
"your CA. It prompts later for the certificate and stores it in a" \
"reasonable place."
echo "Tested only with StartSSL."
exit 1
@ntrrgc
ntrrgc / wallpapers.sh
Created August 11, 2015 23:28
Find images susceptible of being used as wallpaper
#!/bin/bash
min_ratio=$(bc -l <<< 4/3)
max_ratio=$(bc -l <<< 20/9)
min_height=720
images=()
for f in *.png *.jpg; do
read ratio height <<<$(identify -format '%[fx:w/h] %[fx:h]' "$f")
if (( $(bc <<< "$ratio >= $min_ratio && $ratio <= $max_ratio \
&& $height >= $min_height") == 1)); then
@ntrrgc
ntrrgc / wallpapers.c
Last active August 29, 2015 14:27
Find images susceptible of being used as wallpaper. The hard way, in C.
#define _BSD_SOURCE
#define _POSIX_C_SOURCE 200809L
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <dirent.h>
#include <endian.h>
#include <stdint.h>
#include <sys/stat.h>
@ntrrgc
ntrrgc / base_dir.sh
Created August 18, 2015 18:44
Get the directory where the script resides
# http://stackoverflow.com/a/22614738/1777162
SCRIPT=$( readlink -m $( type -p "$0" )) # Full path to script
BASE_DIR=`dirname "${SCRIPT}"` # Directory script is run in
NAME=`basename "${SCRIPT}"` # Actual name of script even if linked