A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.
posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord| #!/bin/bash | |
| # Script to update a firewall rule in a Hetzner Firewall with your current IP address. | |
| # Good if you would like to restrict SSH access only for your current IP address (secure). | |
| ################# | |
| # WARNING: This script will overwrite all rules in the firewall rules, so make sure you | |
| # added all the required rules. | |
| # I use a separate firewall rule just for SSH access. | |
| ################# |
| -- The goal of this script is to trim messages that have been processed by | |
| -- all extant groups from the a given Redis stream. It returns the number | |
| -- of messages that were deleted from the stream, if any. I make no | |
| -- guarantees about its performance, particularly if the stream is large | |
| -- and not fully processed (so a simple XTRIM isn't possible). | |
| -- First off, bail out early if the stream doesn't exist. | |
| if redis.call("EXISTS", KEYS[1]) == 0 then | |
| return false | |
| end |
| ## Context + metadata | |
| shared_context 'Logged as a user', role: true do | |
| let(:user) { |example| create :user, example.metadata[:role] } | |
| before { login_as user } | |
| end | |
| scenario "Login as a client", role: :client | |
| scenario "Login as a customer", role: :customer | |
| scenario "Login as an admin", role: :admin |
This gist will collects all issues we solved with Rails 5.2 and Webpacker
# Last few parameters(--skip-* part) is only my habbit not actully required
$ rails new <project_name> --webpack=stimulus --database=postgresql --skip-coffee --skip-test| wget https://storage.googleapis.com/golang/go1.10.1.linux-armv6l.tar.gz | |
| sudo tar -C /usr/local -xvf go1.10.1.linux-armv6l.tar.gz | |
| cat >> ~/.bashrc << 'EOF' | |
| export GOPATH=$HOME/go | |
| export PATH=/usr/local/go/bin:$PATH:$GOPATH/bin | |
| EOF | |
| source ~/.bashrc |
| defmodule MyApp.Auth do | |
| import Comeonin.Bcrypt, only: [checkpw: 2, dummy_checkpw: 0] | |
| alias MyApp.Accounts.User | |
| alias MyApp.Repo | |
| def login(conn, user) do | |
| conn | |
| |> Guardian.Plug.sign_in(user) | |
| end |
| # http://adventofcode.com/2017/day/1 | |
| defmodule Day1 do | |
| def sum1(digits), do: | |
| digits | |
| |> Stream.concat(Enum.take(digits, 1)) | |
| |> Stream.chunk_every(2, 1, :discard) | |
| |> Stream.filter(&match?([el, el], &1)) | |
| |> Stream.map(&hd(&1)) | |
| |> Enum.sum() |
| 1. Change rails version in Gemfile | |
| > gem 'rails', '~> 5.1', '>= 5.1.4' | |
| 2. Remove Gemfile.lock | |
| > git rm Gemfile.lock | |
| 3. Run bundle install command | |
| > bundle install --jobs=5 | |
| 4. Run rails' app update to apply changes to app |
| // how to run: | |
| // go run mqtt.go tcp://iot.eclipse.org:1883 /topic/name | |
| package main | |
| import ( | |
| "os" | |
| mqtt "github.com/eclipse/paho.mqtt.golang" | |
| "github.com/gizak/termui" | |
| ) |