Skip to content

Instantly share code, notes, and snippets.

View kofronpi's full-sized avatar

Pierre-Alexandre Kofron kofronpi

View GitHub Profile
jwhiting / warmup.rb
Created May 14, 2018 22:00
Warming up EBS volumes on RDS replicas/snapshots (ruby script)
#!/usr/bin/env ruby
require 'pg'
when creating a postgres db replica in RDS, or restoring from a snapshot, the
underlying EBS volume of the new instance must be initialized by reading every
block, otherwise the blocks will be lazy-initialized by production queries
which will be extremely latent. (i've seen normally 50ms queries take 30s in
# config/initializers/activestorage.rb
Rails.application.config.to_prepare do
# Provides the class-level DSL for declaring that an Active Record model has attached blobs.
ActiveStorage::Attached::Macros.module_eval do
def has_one_attached(name, dependent: :purge_later, acl: :private)
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}
@active_storage_attached_#{name} ||="#{name}", self, dependent: #{dependent == :purge_later ? ":purge_later" : "false"}, acl: "#{acl}")
brambow / postgis-to-geojson-feature-collection.sql
Last active April 25, 2023 15:44
PostGIS query to build a GeoJSON FeatureCollection
SELECT json_build_object(
'type', 'FeatureCollection',
'crs', json_build_object(
'type', 'name',
'properties', json_build_object(
'name', 'EPSG:4326'
'features', json_agg(
mankind / rails-jsonb-queries
Last active April 17, 2024 12:14
Ruby on Rails-5 postgresql-9.6 jsonb queries
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
alexellis / base.Dockerfile
Last active March 16, 2021 12:36
Docker swarm service to mine into the Nice Hash pool
# Published on Docker Hub with above user alexellisio.
# If you want to rebuild your own copy, follow below instructions
# Build this on each type of machine so you have the correct CPU extensions.
FROM alexellisio/boostbase
RUN git clone -b Linux
RUN cd nheqminer/cpu_xenoncat/Linux/asm/ && sh && cd ../../../Linux_cmake/nheqminer_cpu && cmake . && make
ENTRYPOINT ["./nheqminer/Linux_cmake/nheqminer_cpu/nheqminer_cpu"]
the-bass / application.html.erb
Last active April 15, 2020 15:01
Using Google Analytics with Rails 5 and Turbolinks 5. This code is taken from the conversation between @preetpalS and @packagethief on
<%# Put this code snippet between the <head></head>-tags in your application layout and %>
<%# replace 'UA-XXXXXXXX-X' with your own unique Google Analytics Tracking ID %>
<%# ... %>
<%# ... %>
<% if Rails.env.production? %>
<script type="text/javascript">
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
bibendi /
Last active May 8, 2018 05:03
Kontena rails app



$ gem install kontena-cli
$ kontena login {ip}
$ kontena grid use staging
$ kontena vpn config > kontena.ovpn
$ sudo openvpn --config kontena.ovpn --script-security 2 --daemon
L.TileLayer.GeoJSON.Multi = L.TileLayer.GeoJSON.extend({
addTileData: function(json, tilePoint) {
for (var featureName in json) {
var geojson = json[featureName];
L.TileLayer.GeoJSON.prototype.addTileData.apply(geojson, tilePoint);
wnstn / gulpfile.js
Created January 22, 2016 14:26
Rails, Gulp, and Browsersync together at last
var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var setupWatchers = function() {['./app/views/**/*.erb',
'./app/assets/javascripts/**/*.js'], ['reload']);['./app/assets/stylesheets/**/*.scss'], ['reloadCSS'])
gulp.task('reload', function(){
// slack2html
// by @levelsio