Skip to content

Instantly share code, notes, and snippets.

View alexpirine's full-sized avatar
🍄

Alexandre Syenchuk alexpirine

🍄
View GitHub Profile
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:
@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)
@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 / 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 / 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 / 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 / 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
@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;