Skip to content

Instantly share code, notes, and snippets.

View gergelypolonkai's full-sized avatar

Gergely Polonkai gergelypolonkai

View GitHub Profile
@gergelypolonkai
gergelypolonkai / haversine.sql
Created April 27, 2015 07:59
MySQL Haversine function
DELIMITER $$
CREATE FUNCTION `haversine` (lng1 FLOAT, lat1 FLOAT, lng2 FLOAT, lat2 FLOAT)
RETURNS float NO SQL DETERMINISTIC
BEGIN
SET @a = ABS(POWER(SIN(RADIANS(lat1 - lat2)) / 2, 2) + COS(RADIANS(lat1)) * COS(RADIANS(lat2)) * POWER(SIN(RADIANS(lng1 - lng2)) / 2, 2));
RETURN 12756.200 * ATAN2(SQRT(@a), SQRT(1 - @a));
END$$
@gergelypolonkai
gergelypolonkai / DynarrayConfiguration.php
Created April 27, 2015 08:22
Symfony 2 configuration: array of dynamic associative arrays
<?php
$rootNode
->children()
->arrayNode('state_machine')
->requiresAtLeastOneElement()
->beforeNormalization()
->ifArray()
->then(function($values) {
$ret = array();
@gergelypolonkai
gergelypolonkai / redirect-non-existing.conf
Created April 27, 2015 08:28
Redirect only non-existing files with Apache
RewriteEngine on
RewriteRule ^/$ http://172.16.72.131:8080/ [QSA,L,P]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/(.*) http://172.16.72.131:8080/$1 [QSA,L,P]
Order allow,deny
Allow from all
@gergelypolonkai
gergelypolonkai / WhatEver.php
Created April 27, 2015 08:40
Role and class based ACLs with Symfony 2
<?php
$this->get('security.context')->isGranted('ROLE_ADMIN');
@gergelypolonkai
gergelypolonkai / client-state.c
Created April 27, 2015 08:47
Registering a GLib ENumType
#include "wmudclientstate.h"
GType
wmud_client_state_get_type (void)
{
static volatile gsize g_define_type_id__volatile = 0;
if (g_once_init_enter(&g_define_type_id__volatile)) {
static const GEnumValue values[] = {
{ WMUD_CLIENT_STATE_FRESH, "WMUD_CLIENT_STATE_FRESH", "fresh" },
@gergelypolonkai
gergelypolonkai / Makefile
Created April 27, 2015 08:54
Registering a GLib EnumType using glib-mkenums and GNU Autotools
gswe_enum_headers = headers-that-contain-enums.h
gswe-enumtypes.h: $(gswe_enum_headers) gswe-enumtypes.h.template
$(GLIB_MKENUMS) --template $(filter %.template,$^) $(filter-out %.template,$^) > \
gswe-enumtypes.h.tmp && mv gswe-enumtypes.h.tmp gswe-enumtypes.h
gswe-enumtypes.c: $(gswe_enum_headers) gswe-enumtypes.h gswe-enumtypes.c.template
$(GLIB_MKENUMS) --template $(filter %.template,$^) $(filter-out %.template,$^) > \
gswe-enumtypes.c.tmp && mv gswe-enumtypes.c.tmp gswe-enumtypes.c
@gergelypolonkai
gergelypolonkai / border-radius.sass
Created April 27, 2015 20:19
Cross-browser border radius mixin in SASS with variable parameters
=border-width($t, $r: $t, $b: $t, $l: $r)
border-top-width: $t
border-right-width: $r
border-bottom-width: $b
border-left-width: $l
=border-top-right-radius($value)
border-top-right-radius: $value
-moz-border-top-right-radius: $value
-webkit-border-top-right-radius: $value
@gergelypolonkai
gergelypolonkai / helper.py
Last active August 29, 2015 14:22
@ParamConverter à la Django
# -*- coding: utf-8 -*-
import re
from django.shortcuts import get_object_or_404
from django.db import models
def convert_params(*params_to_convert, **options):
"""
Convert parameters to objects. Each parameter to this decorator
@gergelypolonkai
gergelypolonkai / README.md
Last active November 10, 2015 08:18
Expandable Widget for Dashing.io

An expandable widget base type for Dashing.io

Usage

Add data-expsizex and data-expsizey to the widget <li> tag:

<li data-row="1" data-col="1" data-sizex="1" data-sizey="1" data-expsizex="2" data-expsizey="2">
@gergelypolonkai
gergelypolonkai / README.md
Created November 30, 2015 14:15
gcov-blame

gcov-blame

A bash/zsh function to visualise coverage data for projects built with GNU libtool.

Usage

gcov-blame src/source-file.c

This will generate the appropriate .gcov file and display it in the terminal. The coverage data should be generated by whatever means first (e.g. make check).