Skip to content

Instantly share code, notes, and snippets.

View alexpirine's full-sized avatar
🍄

Alexandre Syenchuk alexpirine

🍄
View GitHub Profile
@alexpirine
alexpirine / wordpress_repair.php
Last active October 2, 2015 18:38
Deletes postmeta duplicates
<?php
# Copyright Alexandre Syenchuk, 2012
# a multi-site, multi-duplicates version of https://gist.github.com/1177018
header('Content-type: text/plain; charset=utf-8');
include('wp-config.php');
include('wp-load.php');
global $wpdb;
@alexpirine
alexpirine / safealloc.c
Created June 15, 2012 15:38
Safe memory allocation in C
void * safe_malloc(size_t const size)
{
void * p = malloc(size);
if (p == NULL) {
fprintf(stderr, "Out of memory\n");
exit(1);
}
return p;
@alexpirine
alexpirine / gist:5874040
Created June 27, 2013 04:54
<input> pattern for entering prices
<input type="text" class="input-float" pattern="\d+((,|\.)\d\d?)*" />
@alexpirine
alexpirine / gist:5874077
Last active December 19, 2015 01:09
Reverse the order of lines in a file using coreutils and moreutils
tac somefile | sponge somefile
@alexpirine
alexpirine / fizzbuzz.py
Last active December 19, 2015 12:59
FizzBuzz
# 1 min 20 s (including login and tests)
for k in range(1, 101):
if not k % 3 and not k % 5:
print "FizzBuzz"
elif not k % 3:
print "Fizz"
elif not k % 5:
print "Buzz"
else:
print k
@alexpirine
alexpirine / logtemp.py
Last active December 20, 2015 15:08
Trivial server temperature logger using lm-sensors in python
# coding: utf-8
import re
import subprocess
import time
LOG_FILE = '/var/log/temperature.csv'
res = subprocess.check_output(['sensors'])
res = re.findall(r':\s+\+(\d\d\.\d)°C', res)
The MIT License (MIT)
Copyright (c) 2013 Alexandre Syenchuk
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
// -*- coding: utf-8; tab-width: 2; indent-tabs-mode: nil; -*-
//
// Generates Wi-Fi passwords generated in the web interface of the “La box de
// SFR” home router.
//
// In many browsers, this implementation is broken because of a very short
// period of the pseudo-random Math.random() funciton, usually around 2^30.
//
// You can generate a passwords file of several gigabytes and run a
// successfull bruteforce attack in a couple of hours against A WPA key.
@alexpirine
alexpirine / code128.py
Last active December 28, 2015 09:19
Produces SVG containing a Code 128 barcode
modes = {
'A': (
' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-',
'.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', ';',
'<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '\x00', '\x01', '\x02',
'\x03', '\x04', '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A', '\x0B',
'\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11', '\x12', '\x13', '\x14',
'\x15', '\x16', '\x17', '\x18', '\x19', '\x1A', '\x1B', '\x1C', '\x1D',
@alexpirine
alexpirine / decrypt_cf_email.py
Last active February 9, 2016 15:27
Decrypts a cloudflare-encrypted e-mail
def decrypt_cf_email(email):
# a small python function that decrypts a cloudflare-encrypted e-mail
email_key = int(email[:2], 16)
email_chars = [chr(int(email[k:k+2], 16) ^ email_key) for k in range(2, len(email), 2)]
return ''.join(email_chars)