Skip to content

Instantly share code, notes, and snippets.

Loic loicginoux

Block or report user

Report or block loicginoux

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View inoice_number_generator.rb
# generate invoice number in a sequential mode
# using redis and redlock gem
# ex:
# Accounting::InvoiceNumberGenerator::Base.new.lock do |next_number|
#. # create your invoice here
# end
class Accounting::InvoiceNumberGenerator::Base
LOCK_TIMEOUT = 10000
FIRST_NUM_SEQUENCE = 100
@loicginoux
loicginoux / firebase-messaging-sw.js
Last active Jun 3, 2019
Adding FCM to an html page to receive notifications and sending then via FCM ruby gem. (edit: HTTPS needed!)
View firebase-messaging-sw.js
// [START initialize_firebase_in_sw]
// Give the service worker access to Firebase Messaging.
// Note that you can only use Firebase Messaging here, other Firebase libraries
// are not available in the service worker.
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-app.js');
importScripts('https://www.gstatic.com/firebasejs/3.5.2/firebase-messaging.js');
// Initialize the Firebase app in the service worker by passing in the
// messagingSenderId.
firebase.initializeApp({
@loicginoux
loicginoux / explanation.md
Last active Jul 6, 2017
Integrate Bootsy rich text editor with rails admin
View explanation.md

Gemfile

gem "rails_admin"
gem 'bootsy'

/app/assets/javascripts/rails_admin/custom/ui.js

@loicginoux
loicginoux / batch update indentation 4 spaces -> 2 spaces
Last active Jun 22, 2017
find all html files and change indentation from 4 spaces by 2 spaces
View batch update indentation 4 spaces -> 2 spaces
# find all html files in a directory and update indentation
find . -iregex '.*/.*\.html' -exec perl -pi -e 's{^((?: {4})*)}{" " x (2*length($1)/4)}e' {} \;
# update ndentation for one file
perl -pi -e 's{^((?: {4})*)}{" " x (2*length($1)/4)}e' yourfile.js
@loicginoux
loicginoux / gist:6ed431eb9abcdfcb10e0
Created Dec 15, 2014
get AWIS - alexa rank from amazon api
View gist:6ed431eb9abcdfcb10e0
BASE_URL = "http://awis.amazonaws.com/"
access_key_id = AppConfig.get_value('aws_access_key_id')
secret_access_key = AppConfig.get_value('aws_secret_access_key')
now = Time.now.utc.iso8601
url = "yahoo.com"
query = {'AWSAccessKeyId' =>access_key_id,
'Action' => "UrlInfo",
'ResponseGroup' => "Rank",
'SignatureMethod' => "HmacSHA1",
'SignatureVersion' => 2,
View yahoo_boss_test_api.rb
require 'net/http'
include HTTParty
# test app
YAHOO_CONFIG = {
client_id: "YOUR APP ID",
client_secret: "YOUR APP SECRET"
}
@loicginoux
loicginoux / testing authorisation flow with doorkeeper
Created May 29, 2014
testing authorisation flow with doorkeeper
View testing authorisation flow with doorkeeper
require 'oauth2'
client_id = '...'
client_secret = '...'
redirect_uri = "urn:ietf:wg:oauth:2.0:oob"
site = "http://localhost:3000"
client = OAuth2::Client.new(client_id, client_secret, :site => site)
# client.auth_code.authorize_url(:redirect_uri => redirect_uri)
View a simple key value model for rails
##########################################
# Use cases:
# setting a config variable: Variable[:my_key] = 1
# getting a config variable: Variable[:my_key]
# retrieving all keys: Variable.keys
# deleting a key: Variable.delete!(:my_key)
# checking existence: Variable.exists?(:my_key)
# clear all keys: Variable.clear!
#
# Values are transformed to yaml before stored
@loicginoux
loicginoux / gist:5577498
Created May 14, 2013
paste this into your app/assets/stylesheets/active_admin.css.scss to get Rich editor styling correct in Active Admin
View gist:5577498
body.active_admin {
.cke_chrome {
width: 76% !important;
overflow: hidden;
}
.cke_dialog_background_cover{
background-color: black !important;
}
}
body.active_admin {
You can’t perform that action at this time.