Skip to content

Instantly share code, notes, and snippets.

View golgote's full-sized avatar

Bertrand Mansion golgote

  • Mamasam
  • Vincennes, France
View GitHub Profile
<?
function get_avatar_from_service($service, $userid, $size) {
// Based on original Javascript function at https://gist.github.com/jcsrb/1081548
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter (via avatars.io) use get_avatar_from_service('twitter', username, default )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
@golgote
golgote / readcookie.js
Created September 9, 2014 12:17
Fast function to read cookies in javascript browser
function readcookie(a, b, c) {
b = '; ' + document.cookie;
c = b.split('; ' + a + '=');
return !!(c.length - 1) ? c.pop().split(';').shift() : '';
}
@golgote
golgote / partition_trigger.sql.lua
Created October 9, 2014 18:55
PLlua procedure and trigger to automatically create partition tables in Postgresql
--- vim: set nosta noet ts=4 sw=4 ft=lua:
---
--- Hello. I'm a partitioner that puts rows into dated tables, segmented by date ranges.
--- Install me like so on your master table, as a db admin user (for the security definer):
---
--- CREATE TRIGGER auto_partition BEFORE INSERT ON [table] FOR EACH ROW EXECUTE PROCEDURE auto_partition()
---
CREATE OR REPLACE FUNCTION clear_partition_cache()
RETURNS boolean
--
-- PostgreSQL database dump
--
-- Dumped from database version 9.1.1
-- Dumped by pg_dump version 9.1.1
-- Started on 2011-11-02 16:53:36 EET
SET statement_timeout = 0;
SET client_encoding = 'UTF8';
--------------------------------------------------------------------------------
-- PHP-style serialization in PostgreSQL
-- Making a better situation of someone else's bad decision
-- See examples at bottom
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Serialization function per type
CREATE OR REPLACE FUNCTION php_serialize(boolean) RETURNS text
@golgote
golgote / Article.rb
Last active August 29, 2015 14:12 — forked from otobrglez/Article.rb
# This method finds related articles using Jaccard index (optimized for PostgreSQL).
# More info: http://en.wikipedia.org/wiki/Jaccard_index
class Article < ActiveRecord::Base
def related(limit=10)
Article.find_by_sql(%Q{
SELECT
a.*,
( SELECT array_agg(t.name) FROM taggings tg, tags t
<?php
class ImageDiff {
// not bigger 20
private $matrix = 15;
public function getImageInfo($image_path){
list($width, $height, $type, $attr) = getimagesize($image_path);
$image_type = '';
# example location parts of nginx.conf
# add your own AWS keys, server lines etc, and set your aws domains, paths
http {
# you will need the luacrypto in the cpath, download from http://luacrypto.luaforge.net/
lua_package_cpath "/home/justin/lua/luacrypto-0.2.0/src/l?.so.0.2.0;;";
server {
listen 80;
@golgote
golgote / config.json
Last active August 29, 2015 14:22 — forked from anonymous/config.json
{
"vars": {
"@gray-base": "#000",
"@gray-darker": "lighten(@gray-base, 13.5%)",
"@gray-dark": "lighten(@gray-base, 20%)",
"@gray": "lighten(@gray-base, 33.5%)",
"@gray-light": "lighten(@gray-base, 46.7%)",
"@gray-lighter": "lighten(@gray-base, 93.5%)",
"@brand-primary": "darken(#428bca, 6.5%)",
"@brand-success": "#5cb85c",
@golgote
golgote / random_string.lua
Last active September 6, 2015 08:29
Random string function for PL/Lua
CREATE OR REPLACE FUNCTION random_string_pllua(string_length INTEGER, lowercase BOOLEAN DEFAULT false) RETURNS text
LANGUAGE pllua VOLATILE
AS $$
-- math.randomseed(socket.gettime()) -- seems to be needed by luajit only
local alnum = {
'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',
'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'