Skip to content

Instantly share code, notes, and snippets.

View kmaksimovv's full-sized avatar

Konstantin Maksimov kmaksimovv

  • Russian Federation
View GitHub Profile
@aleksevd
aleksevd / _form.html.slim
Created September 14, 2018 18:47
Courses
= simple_form_for [:admin, @course], wrapper: :horizontal_form, html: { class: 'form-horizontal' } do |f|
= f.input :name
= f.input :description
= f.association :teacher, label_method: :last_name
= f.association :disciplines
.row
.col-md-11.col-md-offset-3.button_box
= f.button :submit, 'Сохранить', class: 'btn btn-primary'
= link_to 'Отменить', admin_courses_path, class: 'btn btn-default'
@sonhmai
sonhmai / kafka
Last active March 27, 2025 06:55
kafka basic commands
# BENCHMARK-----------------------------------------------------
#1. Rust kafka-benchmark (https://github.com/fede1024/kafka-benchmark)
# must create topic with 6 partitions first
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 6--topic [scenario]
# replace scenario with one in file kafka-benchmark/config/base_producer.yaml
@satendra02
satendra02 / app.DockerFile
Last active November 19, 2024 17:28
docker+rails+puma+nginx+postgres (Production ready)
FROM ruby:2.3.1
# Install dependencies
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
# Set an environment variable where the Rails app is installed to inside of Docker image:
ENV RAILS_ROOT /var/www/app_name
RUN mkdir -p $RAILS_ROOT
# Set working directory, where the commands will be ran:
@nav-mike
nav-mike / docker.md
Last active May 3, 2021 07:12
Использование docker compose с rails

Использование docker compose с rails + postgresql

Настройка проекта

Прежде чем начать, убедитесь, что у вас установлен docker и docker-compose, если же нет, то используйте ссылки в конце документа.

Для использования docker в своем проекте, первое, что нужно сделать, это добавить Dockerfile. Этот файл описывает процесс сборки контейнера для вашего проекта. В нем указываются настройки сборки и инструкции для установки зависимостей.

Пример такого файла для простого rails-проекта:

@fjahr
fjahr / application.html.erb
Last active October 4, 2021 10:35 — forked from suryart/application.html.erb
Displaying Rails 5 flash messages with Twitter Bootstrap 4 (last tested on Alpha-v6). Updated version of https://gist.github.com/suryart/7418454
// layout file
<body>
<div class="container">
<%= flash_messages %>
<%= yield %>
</div><!-- /container -->
</body>
@trandaison
trandaison / whenever.md
Last active January 15, 2020 17:08
Simple example about Whenever gem

#Add sidekiq, sinatra and whenever to the Gemfile

gem 'sidekiq'
gem 'sinatra', require: false
gem "whenever", require: false

Then install the gem

$ bundle install
@AtulKsol
AtulKsol / psql-error-fix.md
Last active September 30, 2025 18:28
Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from

@rpanachi
rpanachi / db.rake
Created April 10, 2016 21:26
Rakefile for Sequel database operations
namespace :db do
require 'sequel'
Sequel.extension(:migration)
MIGRATIONS_PATH = 'db/migrations'
def db_conn_env
ENV["BOOKSHELF_DATABASE_URL"]
end
@miholeus
miholeus / WordCount.java
Created January 7, 2016 21:35
Hadoop WordCount example
import java.io.IOException;
import java.util.*;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.conf.*;
import org.apache.hadoop.io.*;
import org.apache.hadoop.mapreduce.*;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

Rails 5 and ActionCable

Assumptions: The application already exists. You have two models article.rb and comment.rb. Articles have two attributes, title and text. Comments have two attributes, text and article_id. See these instructions if you need help getting started.

Routes

Assuming that you are nesting your :comments resources inside of :articles, mount ActionCable and make sure you have a root.

config/routes.rb

Rails.application.routes.draw do