Skip to content

Instantly share code, notes, and snippets.

View hubertlepicki's full-sized avatar

Hubert Łępicki hubertlepicki

View GitHub Profile
@hubertlepicki
hubertlepicki / config.lua
Created January 16, 2024 13:24
My LunarVim config.lua file
-- Read the docs: https://www.lunarvim.org/docs/configuration
-- Example configs: https://github.com/LunarVim/starter.lvim
-- Video Tutorials: https://www.youtube.com/watch?v=sFA9kX-Ud_c&list=PLhoH5vyxr6QqGu0i7tt_XoVK9v-KvZ3m6
-- Forum: https://www.reddit.com/r/lunarvim/
-- Discord: https://discord.com/invite/Xb9B4Ny
--
-- Additional NeoVim plugins:
defmodule UI.Application do
use Application
def start(_type, _args) do
# List of children to be started when checks succeed
delayed_children = [
UI.Endpoint,
{Absinthe.Subscription, UI.Endpoint}
]
@hubertlepicki
hubertlepicki / benchmark.ex
Last active March 15, 2019 10:54
benchmark
query = "query {
project(id: 1389) {
id,
slices {
id,
todos {
id,
title,
description,
progress,
For 2 people will need:
1. Spices
- 1 table spoon of red curry paste
- 2 anise stars
- 3 cardamom seeds
- 3 cloves
- 1 piece of cinnamon bark
- 1 long pepper
- 2 table spoons of garam masala
@hubertlepicki
hubertlepicki / db_connection_dies
Last active October 13, 2017 08:03
Phoenix stacktraces
09:46:57.136 [error] #PID<0.600.0> running Todos.UI.Endpoint terminated
Server: localhost:4001 (http)
Request: POST /login
** (exit) an exception was raised:
** (DBConnection.ConnectionError) connection not available because of disconnection
(db_connection) lib/db_connection.ex:926: DBConnection.checkout/2
(db_connection) lib/db_connection.ex:742: DBConnection.run/3
(db_connection) lib/db_connection.ex:584: DBConnection.prepare_execute/4
(ecto) lib/ecto/adapters/postgres/connection.ex:73: Ecto.Adapters.Postgres.Connection.prepare_execute/5
(ecto) lib/ecto/adapters/sql.ex:256: Ecto.Adapters.SQL.sql_call/6
@hubertlepicki
hubertlepicki / irb
Created September 29, 2017 11:43
Strings vs Symbols ruby hash
irb(main):029:0> Benchmark.bm do |x|
irb(main):030:1* x.report("Strings: ") { 10000000.times {"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".hash} }
irb(main):031:1> x.report("Symbols: ") { 10000000.times {:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.hash} }
irb(main):032:1> end
user system total real
Strings: 1.290000 0.000000 1.290000 ( 1.282911)
Symbols: 0.450000 0.000000 0.450000 ( 0.458915)
@hubertlepicki
hubertlepicki / Dockerfile
Created June 13, 2017 08:51
Ruby 2.4.1, Rails 5.1.1, PostgreSQL, Docker + docker-compose config files
FROM phusion/baseimage:0.9.22
CMD ["/sbin/my_init"]
RUN add-apt-repository -y ppa:brightbox/ruby-ng
RUN apt-get update
RUN apt-get install -y libpq-dev git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libxml2-dev libxslt1-dev libcurl4-openssl-dev software-properties-common libffi-dev nodejs wget autoconf tzdata ruby2.4 ruby2.4-dev rubygems ruby-switch
RUN ruby-switch --set ruby2.4
RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
@hubertlepicki
hubertlepicki / gracefully_shutdown_process_tree.exs
Last active May 18, 2017 07:45
Gracefully shut down the process tree with name registration
defmodule ParentServer do
use GenServer
import Supervisor.Spec
def start_link() do
GenServer.start_link(__MODULE__, nil, name: __MODULE__)
end
def init(_) do
Process.flag(:trap_exit, true)
@hubertlepicki
hubertlepicki / application_controller.rb
Last active April 7, 2017 15:31
Simple ActiveRecord query cache
class ApplicationController < ActionController::Base
...
around_action :use_request_cache, if: Proc.new {|c| request.get? }
private
def use_request_cache
RequestCache.with_cache do
yield
@hubertlepicki
hubertlepicki / bench.ex
Last active February 8, 2017 13:52 — forked from obrok/bench.ex
defmodule Bench do
def bench do
:timer.tc(fn -> Enum.reduce(Range.new(0, 10000000), 0, &Kernel.+/2) end) |> IO.inspect
:timer.tc(fn -> Enum.reduce(Range.new(0, 10000000), 0, fn acc, n -> acc + n end) end) |> IO.inspect
:timer.tc(fn -> Enum.reduce(Range.new(0, 10000000), 0, &(&1 + &2)) end) |> IO.inspect
nil
end
end