Skip to content

Instantly share code, notes, and snippets.

View loicginoux's full-sized avatar

Loic loicginoux

View GitHub Profile
@loicginoux
loicginoux / gist:5577498
Created May 14, 2013 16:50
paste this into your app/assets/stylesheets/active_admin.css.scss to get Rich editor styling correct in Active Admin
body.active_admin {
.cke_chrome {
width: 76% !important;
overflow: hidden;
}
.cke_dialog_background_cover{
background-color: black !important;
}
}
body.active_admin {
##########################################
# 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 / testing authorisation flow with doorkeeper
Created May 29, 2014 11:51
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)
@loicginoux
loicginoux / yahoo_boss_test_api.rb
Created August 20, 2014 11:03
yahoo boss test api
require 'net/http'
include HTTParty
# test app
YAHOO_CONFIG = {
client_id: "YOUR APP ID",
client_secret: "YOUR APP SECRET"
}
@loicginoux
loicginoux / gist:6ed431eb9abcdfcb10e0
Created December 15, 2014 12:46
get AWIS - alexa rank from amazon api
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,
@loicginoux
loicginoux / batch update indentation 4 spaces -> 2 spaces
Last active June 22, 2017 09:34
find all html files and change indentation from 4 spaces by 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 / explanation.md
Last active July 1, 2023 11:22
Integrate Bootsy rich text editor with rails admin

Gemfile

gem "rails_admin"
gem 'bootsy'

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

@loicginoux
loicginoux / firebase-messaging-sw.js
Last active June 11, 2024 02:39
Adding FCM to an html page to receive notifications and sending then via FCM ruby gem. (edit: HTTPS needed!)
// [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 / inoice_number_generator.rb
Created February 13, 2019 17:55
invoice number generator
# 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 / active_record_log_subscriber.rb
Last active September 24, 2019 10:48
how to know which sql query comes from which line of code
# file config/initializers/active_record_log_subscriber.rb
###
# log result:
# Alert Load (0.8ms) SELECT `alerts`.* FROM `alerts` INNER JOIN `sharings` ON `alerts`.`id` = `sharings`.`alert_id` WHERE `sharings`.`user_id` = 37 AND `alerts`.`id` = 54148 AND (status = 0) LIMIT 1
# ↳ app/controllers/entries_controller.rb:20:in `set_objects'
# source: http://www.jkfill.com/2015/02/14/log-which-line-caused-a-query/
###
module LogQuerySource
def debug(*args, &block)