Skip to content

Instantly share code, notes, and snippets.

@BinaryPrison
BinaryPrison / gist:1616952
Last active September 29, 2015 14:47
Custom look for scroll bar (only for Chrome)
body { padding: 50px; }
ul {
max-height:300px;
overflow:auto;
}
/* Overwrite the default to keep the scrollbar always visible */
::-webkit-scrollbar {
@BinaryPrison
BinaryPrison / gist:1112092
Created July 28, 2011 17:48
Fast add nanoseconds to timespec structure
static inline uint32_t __iter_div_u64_rem(uint64_t dividend, uint32_t divisor, uint64_t *remainder)
{
uint32_t ret = 0;
while (dividend >= divisor) {
/* The following asm() prevents the compiler from
optimising this loop into a modulo operation. */
asm("" : "+rm"(dividend));
dividend -= divisor;
@BinaryPrison
BinaryPrison / gist:1112084
Created July 28, 2011 17:45
Signal level(dBov) for PCM sample
static inline int16_t get_average_signal_level(const unsigned char* buffer, uint16_t buffer_size)
{
int sum = 0;
uint16_t samples = buffer_size/2;
const short* pcm = (const short*)buffer;
const short* end = pcm + samples;
while(pcm != end)
{
if (*pcm < 0)
sum -= *pcm++;
@BinaryPrison
BinaryPrison / gist:1078121
Last active September 26, 2015 09:47
curl post request example
curl -X POST http://localhost/script.php -d '{"param1":value,"param2":"value"}' -H "Content-type: application/json"
@BinaryPrison
BinaryPrison / iterate_eth_ip_address.cpp
Last active September 26, 2015 08:17
Iterate local ip addresses (linux)
void check_eth_ip_address()
{
struct ifaddrs *ifaddr = NULL;
struct ifaddrs *ifa = NULL;
getifaddrs(&ifaddr);
for (ifa = ifaddr; ifa != NULL; ifa = ifa->ifa_next)
{
if (ifa->ifa_addr->sa_family == AF_INET)