Skip to content

Instantly share code, notes, and snippets.

View basgys's full-sized avatar

Bastien Gysler basgys

View GitHub Profile
@basgys
basgys / Tez
Created December 6, 2021 11:30
I am attesting that this GitHub handle basgys is linked to the Tezos account tz1LvHJjweC8ARpHfATq16ToiXZDAvsNBDNM for tzprofiles
sig:edsigtw5NpWReH1QoSUnWH9fMq9cdpSqNY643GvCxjnFmDf8UfGMD3V24xyPizGR1sjhUQifNhiMquu6Y9wvfrYdiNcEDuWqoKe
package main
import (
"fmt"
"math"
"sort"
"strings"
"github.com/pbnjay/clustering"
)
class UberRelation
include Enumerable
def initialize(scopes)
scopes.kind_of?(Array) or raise ArgumentError.new("Argument scopes is not an array!")
@scopes = scopes
end
def each(&block)
block_given? ? load.each{|scope| block.call(scope)} : load
module SoftDeletable
extend ActiveSupport::Concern
def soft_delete!
find_each do |record|
record.soft_delete!
end
end
included do
@basgys
basgys / aggregate_field.rb
Created September 27, 2013 14:23
This module allows to create a virtual field from multiple fields
# = AggregateField
#
# This module allows to create a virtual field from multiple fields
#
# Example:
#
# class DummyClass
# include AggregateField
#
# attr_accessor :first_name, :last_name
@basgys
basgys / gist:5728380
Last active December 18, 2015 04:49
Wrap mysql2 deadlocks in an ActiveRecord exception
# This core extension aims to manage Deadlocks
# with a proper ActiveRecord exception.
#
# It only works for mysql2
#
# Example:
#
# MyModel.transaction do
# begin
# record1 = MyModel.find(:id, lock: true)
@basgys
basgys / simple_paperclip.rb
Created June 5, 2013 08:25
Use Paperclip without ActiveRecord
# == Paperclip without ActiveRecord
#
# Simple and lightweight object that can use Paperclip
#
#
# Customized part can be extracted in another class which
# would inherit from SimplePaperclip.
#
# class MyClass < SimplePaperclip
# attr_accessor :image_file_name # :<atached_file_name>_file_name
@basgys
basgys / paperclip_background_upload.rb
Created May 1, 2013 07:30
Upload images in background. This is a draft
# has_attached_file :image, configuration
# background_upload_for :image
module PaperclipBackgroundUpload
extend ActiveSupport::Concern
included do
def background
@background || false
end
@basgys
basgys / gist:5356952
Created April 10, 2013 18:02
BundleReader
package ch.hegarc.ig.clientscomptes.configuration;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang3.StringUtils;
@basgys
basgys / gist:4443808
Last active December 10, 2015 13:48
Reload images on failure every x seconds
// Reload images on failure every x seconds
$("img").error(function() {
var path = $(this).data('src');
var img = $(this);
// Put back mock image
$(img).attr('src', 'http://placehold.it/56x56');
// Increment loading counter
var attempt = ($(img).data('attempt') || 0);