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 / matheval.lua
Created March 17, 2019 10:49 — forked from hmenke/matheval.lua
Simple mathematical expression parser and evaluator in Lua with LPEG
local lpeg = require"lpeg"
local C, P, R, S, V = lpeg.C, lpeg.P, lpeg.R, lpeg.S, lpeg.V
local white = S(" \t") ^ 0
local digit = R("09")
local dot = P(".")
local eE = S("eE")
local sign = S("+-")^-1
local mantissa = digit^1 * dot * digit^0 + dot * digit^1 + digit^1
@golgote
golgote / d7install.bash
Created October 11, 2018 21:09 — forked from ricardoamaro/d7install.bash
Drupal Installation Script for Linux Debian/Ubuntu
#!/bin/bash -e
#############################
#
# Auto Install Drupal on Debian/Ubuntu boxes
# Author: ricardo amaro
# https://drupal.org/user/666176
#
# License: http://www.gnu.org/licenses/gpl-2.0.html
#
@golgote
golgote / bindinghandler.js
Created February 26, 2016 13:49 — forked from anonymous/bindinghandler.js
Knockout + bootstrap-tagsinput
ko.bindingHandlers.tagsinput = {
init: function(element, valueAccessor, allBindings) {
var options = allBindings().tagsinputOptions || {};
var value = valueAccessor();
var valueUnwrapped = ko.unwrap(value);
var el = $(element);
el.tagsinput(options);
@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';