Skip to content

Instantly share code, notes, and snippets.

@kokorolx
kokorolx / ror-association.md
Created April 10, 2019 07:20 — forked from kieetnvt/Crying with Rails Associations.md
Crying with Rails Associations

Crying with Rails Associations

Belongs To:

class Post < ApplicationRecord
  belongs_to :user
end

create_table :photos do |t|
@kokorolx
kokorolx / psql-error-fix.md
Created April 10, 2020 02:37 — forked from AtulKsol/psql-error-fix.md
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

@kokorolx
kokorolx / gist:760de934e4a096d493504855b116e60c
Last active April 17, 2020 15:40
Solved Upgrade from Heroku-16 to Heroku-18, wicked_pdf can not print images

Heroku-18 can not work directly with the gem wicked_pdf[https://github.com/mileszs/wicked_pdf]

To resolve this problem, you need to install libssl1.0.0 to your heroku server.

My old Aptfile

tesseract-ocr
tesseract-ocr-eng

My new Aptfile

-- Select last 5 record which is unique by province_name and order by created_at DESC

#
# Table name: listings
#
#  id                   :uuid             not null, primary key
#  province_name        :string
#  province_id          :uuid
#  created_at           :datetime         not null
#
@kokorolx
kokorolx / sublime-merge-command-line.md
Created October 12, 2021 06:42 — forked from SuryaElite/sublime-merge-command-line.md
Launch Sublime Merge from the command line on OSX

Launch Sublime Merge from the command line on OSX

Sublime Merge includes a command line tool, smerge, to work with git, subversion, mercurial projects on the command line. This can be used to open projects in Sublime Merge using the command line.

Requirements

  • Sublime Merge installed in your system within Applications folder

Setup

@kokorolx
kokorolx / base_job.rb
Created August 6, 2023 15:08
Recurring Workers with Rails, Sidekiq and ice_cube
app/sidekiq/recurring_workers/base_job.rb
require 'sidekiq/api'
class RecurringWorkers::BaseJob
include Sidekiq::Job
sidekiq_options queue: "recurring_workers", retry: 3, backtrace: true
def self.schedule_all
@kokorolx
kokorolx / docker-compose.yml
Created August 29, 2024 02:25
Setup mongodb replicaset with docker compose
version: '3.8'
services:
mongo1:
image: mongo:latest
container_name: mongo1
restart: always
ports:
- 27017:27017
environment:
@kokorolx
kokorolx / blog.thnkandgrow.com.conf
Last active September 20, 2024 16:30
Migrate Installed nginx to nginx docker and traefik
# /etc/nginx/site-enables/blog.thnkandgrow.com.conf
server {
# current config
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# ...other config
@kokorolx
kokorolx / csrf-attacks-prevention-and-mitigation-strategies.md
Created February 25, 2025 16:39
Learn about Cross-Site Request Forgery (CSRF) attacks and how to prevent them. Protect your web applications from malicious exploits with effective strategies.

CSRF: Understanding and Preventing Cross-Site Request Forgery Attacks

Author: kokorolx

Protect your web applications from malicious exploits. Learn about CSRF and effective prevention strategies.

What is CSRF (Cross-Site Request Forgery)?

Cross-Site Request Forgery (CSRF), pronounced "sea surf," is a type of web security vulnerability that allows an attacker to trick a user into performing actions they did not intend to perform on a web application in which they are authenticated. Unlike Cross-Site Scripting (XSS), which exploits the user's trust in a website, CSRF exploits the website's trust in a user. Imagine a scenario where a user is logged into their online banking account. A malicious website could embed a hidden form that, when the user visits the site, automatically submits a request to the banking server to transfer funds to the attacker's account. Since the user is already authenticated, the banking server has no way of knowing the reque

@kokorolx
kokorolx / keycloak-what-s-new-alternatives-and-outlook-for-2025.md
Created February 25, 2025 16:49
Explore the 2025 landscape of Keycloak, its updates, alternatives like Auth0 and Okta, and future outlook. Make informed decisions about your IAM solution.

Keycloak: What's New, Alternatives, and Outlook for 2025

By kokorolx

A comprehensive look at the evolving landscape of Keycloak, its recent updates, potential alternatives, and what the future holds for this open-source Identity and Access Management solution in 2025.

Introduction to Keycloak

Keycloak has established itself as a leading open-source Identity and Access Management (IAM) solution, providing features like Single Sign-On (SSO), identity brokering, and social login. As we move into 2025, it's crucial to understand how Keycloak is evolving and whether it remains the best choice for your organization's IAM needs. This blog post will delve into the latest changes in Keycloak, explore viable alternatives, and provide an outlook on its future.