Skip to content

Instantly share code, notes, and snippets.

View golgote's full-sized avatar

Bertrand Mansion golgote

  • Mamasam
  • Vincennes, France
View GitHub Profile
@golgote
golgote / import_module.c
Created December 3, 2011 08:30
PHP C to convert CSV to array found on http://e-normous.com/nerd/import_module.c
/*
compilation:
cc -fPIC -DCOMPILE_DL=1 -I/usr/local/src/php-4.2.3/main/ -I/usr/local/src/php-4.2.3/Zend/ -I/usr/local/src/php-4.2.3/ -I/usr/local/src/php-4.2.3/TSRM import_module.c -c -o import_module.o
gcc -shared -L/usr/local/lib -rdynamic -o import_module.so import_module.o
usage:
- assume headers are in the first row, use them for field titles
dl("/path/to/module");
start_import("/path/to/file");
@golgote
golgote / gist:1347562
Created November 8, 2011 11:40
Use palette.pl in TextMate to output colors used in a CSS file
#!/usr/bin/env ruby
# Palette is a Perl tool that creates a color swatch from a CSS file
# http://code.google.com/p/css-palette/source/browse/trunk/src/palette.pl
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"
palette = ENV["TM_BUNDLE_SUPPORT"] + "/palette.pl"
TextMate.save_current_document
@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'
@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",
# 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;
<?php
class ImageDiff {
// not bigger 20
private $matrix = 15;
public function getImageInfo($image_path){
list($width, $height, $type, $attr) = getimagesize($image_path);
$image_type = '';
@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-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
--
-- 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';
@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