Skip to content

Instantly share code, notes, and snippets.

View piclez's full-sized avatar

Peter WD piclez

View GitHub Profile
@piclez
piclez / series.rb
Created December 1, 2015 01:14
ElasticSearch/Searchkick with custom mappings and analyzer
searchkick callbacks: :async,
word_start: [:name, :customer_name, :studio_name],
merge_mappings: true,
settings: {
analysis: {
analyzer: {
custom_chars: {
type: 'custom',
tokenizer: 'whitespace',
filter: ['lowercase', 'custom_filter']
@piclez
piclez / .pryrc
Created February 2, 2016 00:38
pryrc
if defined?(Pry || PryDebugger)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'f', 'finish'
end
@piclez
piclez / gomongohql.go
Created May 10, 2016 03:29 — forked from IndianGuru/gomongohql.go
gomongohql.go
package main
import (
"fmt"
"html/template"
"labix.org/v2/mgo"
"labix.org/v2/mgo/bson"
"log"
"net/http"
"os"
@piclez
piclez / docker-cleanup.sh
Created October 11, 2016 21:45
docker-cleanup.sh
#!/bin/bash
# Remove exited containers
for exited in $(docker ps -a | grep Exited | cut -d ' ' -f 1); do
docker rm $exited;
done
# Remove intermediate images
for img in $(docker images | grep "<none>" | awk "{print \$3}"); do
docker rmi -f $img;
Warning: require(/var/www/public/../vendor/autoload.php): failed to open stream: No such file or directory in /var/www/public/index.php on line 24
Fatal error: require(): Failed opening required '/var/www/public/../vendor/autoload.php' (include_path='.:/usr/local/lib/php') in /var/www/public/index.php on line 24
@piclez
piclez / nginx.conf
Last active January 7, 2021 19:26
nGinx & Passenger
load_module /usr/local/opt/passenger/libexec/modules/ngx_http_passenger_module.so;
#user nobody;
worker_processes 2;
# worker_rlimit_nofile 30000;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
@piclez
piclez / resize_nocrop_noscale
Created January 8, 2023 03:44 — forked from maxivak/resize_nocrop_noscale
Crop and resize an image using MiniMagick in Ruby on Rails. Two approaches.
def resize_nocrop_noscale(image, w,h)
w_original = image[:width].to_f
h_original = image[:height].to_f
if w_original < w && h_original < h
return image
end
# resize
image.resize("#{w}x#{h}")
@piclez
piclez / bulk_merge.rb
Created February 16, 2023 02:45 — forked from amichal/bulk_merge.rb
csv export and bulk load any rails scope
# Bulk merge a bunch of records
#
# we expect most of the records to import to represent updates
# so this method tries to be efficent with database queries
# by using a single query to find any existing records matching the key_attributes
# updating those records and finally inserting each remaining record
#
# It DOEST NOT use a transaction or lock. callers responsibilty to
# add that if desired
#
@piclez
piclez / listings_controller.rb
Created March 30, 2023 01:36 — forked from dajulia3/listings_controller.rb
Service locator with Rails Initializer for rails service loader that loads the services from a config file.
class ListingsController < ApplicationController
def index
movie_listing_service = ServiceLocator.get_service_instance(:MovieListing)
@available_movies = movie_listing_service.available_movies
render nothing: true #this is just an example don't get hung up on it :)
end