Skip to content

Instantly share code, notes, and snippets.

View syenchuk's full-sized avatar
🏠

Sacha syenchuk

🏠
View GitHub Profile
@syenchuk
syenchuk / 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;
@syenchuk
syenchuk / endianness.c
Created June 15, 2012 15:06
Endianness conversions with positive integers
// converts 32-bits positive integer to 4-bytes little endian
void to4li(unsigned long int const value, char * const buffer)
{
buffer[0] = value >> 8 * 0;
buffer[1] = value >> 8 * 1;
buffer[2] = value >> 8 * 2;
buffer[3] = value >> 8 * 3;
}
// converts 16-bits positive integer to 2-bytes little endian
@syenchuk
syenchuk / 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;
@syenchuk
syenchuk / gist:5874040
Created June 27, 2013 04:54
<input> pattern for entering prices
<input type="text" class="input-float" pattern="\d+((,|\.)\d\d?)*" />
@syenchuk
syenchuk / 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
@syenchuk
syenchuk / 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
@syenchuk
syenchuk / 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.
@syenchuk
syenchuk / 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',