Skip to content

Instantly share code, notes, and snippets.

View pvrt's full-sized avatar

Pavel R pvrt

View GitHub Profile
@klich3
klich3 / iphone-addressbar-gap.html
Created January 25, 2022 12:24
Attach some dom element on the bottom of screen as absolute, triggered to move on resize address bar.
<!--
Author: <Anthony Sychev> (hello at dm211 dot com | a.sychev at jfranc dot studio)
Buy me a coffe: https://www.buymeacoffee.com/twooneone
Untitled-1 (c) 2022
Created: 2022-01-25 20:06:02
Desc: Attach some dom element on the bottom of screen as absolute, triggered to move on resize address bar.
-->
<html>
@hlubek
hlubek / nginx.conf
Created August 12, 2021 12:17
Nginx reverse proxy with caching for Next.js with imgproxy
# Based on https://steveholgado.com/nginx-for-nextjs/
# - /var/cache/nginx sets a directory to store the cached assets
# - levels=1:2 sets up a two‑level directory hierarchy as file access speed can be reduced when too many files are in a single directory
# - keys_zone=STATIC:10m defines a shared memory zone for cache keys named “STATIC” and with a size limit of 10MB (which should be more than enough unless you have thousands of files)
# - inactive=7d is the time that items will remain cached without being accessed (7 days), after which they will be removed
# - use_temp_path=off tells NGINX to write files directly to the cache directory and avoid unnecessary copying of data to a temporary storage area first
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=STATIC:10m inactive=7d use_temp_path=off;
upstream nextjs_upstream {
@gutschilla
gutschilla / install-project-on-fresh-ubuntu.bash.sh
Last active November 8, 2024 22:09
provisioning server for elixir
#! /bin/bash
# I am exporting variables to have them in my shell after I ran the script.
# I find that convenient. Of course, those can/should be removed in "serious" deployments.
# create a time string between "1:00" and "5:59"
export REBOOT_TIME=`perl -e "print scalar(int 1 + 5 * rand) . q[:] . scalar(int 6 * rand) . scalar(int 9 * rand)"`
export HOSTNAME=`hostname`
export NETWORK_DEVICE=eth0 # might be different in cloud servers
@pvrt
pvrt / index.haml
Created March 26, 2019 14:07
Product quantity js counter
.counter
.down{:onclick => "decreaseCount(event, this)"} -
%input{:type => "text", :value => "1"}
.up{:onclick => "increaseCount(event, this)"} +
@pvrt
pvrt / rails_models_cheatsheet.md
Created September 18, 2018 13:53 — forked from romchambe/rails_models_cheatsheet.md
Setup of SSL certificate on Heroku with Gandi

SSL setup: https://vimeo.com/209534466

Creating a join table

rails g migration CreateJoinTableGameInvitesInvitees game_invites invitees

  • Models linked together must be in alphabetical order when naming the migration file
  • The columns can be given any names as long as they are correctly associated in the model file:
has_and_belongs_to_many :invitees, class_name: 'User', foreign_key: 'invitee_id', #the associated column and the alien model
                        join_table: 'game_invites_invitees', #name of the join table
                        association_foreign_key: 'game_invite_id' #the name of the domestic model in the join table
@romchambe
romchambe / rails_models_cheatsheet.md
Last active September 18, 2018 13:53
Setup of SSL certificate on Heroku with Gandi

SSL setup: https://vimeo.com/209534466

Creating a join table

rails g migration CreateJoinTableGameInvitesInvitees game_invites invitees

  • Models linked together must be in alphabetical order when naming the migration file
  • The columns can be given any names as long as they are correctly associated in the model file:
has_and_belongs_to_many :invitees, class_name: 'User', foreign_key: 'invitee_id', #the associated column and the alien model
                        join_table: 'game_invites_invitees', #name of the join table
                        association_foreign_key: 'game_invite_id' #the name of the domestic model in the join table
@marteinn
marteinn / Guardian JWT.md
Last active December 9, 2019 18:46 — forked from nikneroz/Guardian JWT.md
Elixir + Phoenix Framework + Guardian + JWT. This is tutorial and step by step installation guide.

Elixir + Phoenix Framework + Guardian + JWT + Comeonin

This is a updated guide aimed to support Phoenix 1.3 and Guardian 1.0

Preparing environment

We need to generate secret key for development environment.

mix phx.gen.secret
# ednkXywWll1d2svDEpbA39R5kfkc9l96j0+u7A8MgKM+pbwbeDsuYB8MP2WUW1hf
@rlipscombe
rlipscombe / exwx.exs
Created November 26, 2017 16:08
Using wxWidgets from Elixir
#!/usr/bin/env elixir
defmodule Canvas do
@behaviour :wx_object
@title "Canvas Example"
@size {600, 600}
def start_link() do
:wx_object.start_link(__MODULE__, [], [])
@mankind
mankind / rails-jsonb-queries
Last active April 14, 2025 05:43
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#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")
@mileandra
mileandra / letsencrypt_setup.md
Last active April 9, 2020 19:39
Letsencrypt on Ubuntu 16.04 with Nginx, Rails and Capistrano-Unicorn-Nginx

Install Letsencrypt

Install with apt-get

$ sudo apt-get update    
$ sudo apt-get install letsencrypt

Generate a strong DH

$ sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048

Configure nginx