Skip to content

Instantly share code, notes, and snippets.


Bastien Gysler basgys

View GitHub Profile
View Tez
I am attesting that this GitHub handle basgys is linked to the Tezos account tz1LvHJjweC8ARpHfATq16ToiXZDAvsNBDNM for tzprofiles
View clustering.go
package main
import (
View gist:7098697
class UberRelation
include Enumerable
def initialize(scopes)
scopes.kind_of?(Array) or raise"Argument scopes is not an array!")
@scopes = scopes
def each(&block)
block_given? ? load.each{|scope|} : load
View soft_deletable.rb
module SoftDeletable
extend ActiveSupport::Concern
def soft_delete!
find_each do |record|
included do
basgys / aggregate_field.rb
Created Sep 27, 2013
This module allows to create a virtual field from multiple fields
View aggregate_field.rb
# = AggregateField
# This module allows to create a virtual field from multiple fields
# Example:
# class DummyClass
# include AggregateField
# attr_accessor :first_name, :last_name
basgys / gist:5728380
Last active Dec 18, 2015
Wrap mysql2 deadlocks in an ActiveRecord exception
View gist:5728380
# 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 / simple_paperclip.rb
Created Jun 5, 2013
Use Paperclip without ActiveRecord
View simple_paperclip.rb
# == 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 / paperclip_background_upload.rb
Created May 1, 2013
Upload images in background. This is a draft
View paperclip_background_upload.rb
# has_attached_file :image, configuration
# background_upload_for :image
module PaperclipBackgroundUpload
extend ActiveSupport::Concern
included do
def background
@background || false
View gist:5356952
package ch.hegarc.ig.clientscomptes.configuration;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.lang3.StringUtils;
basgys / gist:4443808
Last active Dec 10, 2015
Reload images on failure every x seconds
View gist:4443808
// 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', '');
// Increment loading counter
var attempt = ($(img).data('attempt') || 0);