Skip to content

Instantly share code, notes, and snippets.

View adis-io's full-sized avatar

Adis Osmonov adis-io

View GitHub Profile
@adis-io
adis-io / README.md
Last active January 31, 2023 18:20
Gopass + Chrome + TouchID
@adis-io
adis-io / database_state_loader.rb
Created June 10, 2022 16:32 — forked from keithpitt/database_state_loader.rb
Note that this code only works with PostgreSQL, but it wouldn’t be too hard to adapt our approach for other relational databases.
# Add to `spec/support/database_state_loader.rb`
class DatabaseStateLoader
class EnvironmentError < RuntimeError; end
def self.load(path)
new(path).load
end
def initialize(path)
@adis-io
adis-io / gist:022588f1a989bf2dfa23f5aa08decd34
Created June 10, 2022 11:30 — forked from 13k/gist:3086739
Capybara in Rails Console
# rails console test
# # or
# RAILS_ENV=test rails console
require 'capybara/dsl'
Capybara.app = app.instance_variable_get("@app")
cap = Object.new.instance_eval { extend Capybara::DSL; self }
# cap.visit '/'
# cap.page.find 'h1'
@adis-io
adis-io / Dockerfile
Created May 13, 2022 21:20 — forked from pdonorio/Dockerfile
A template for best practices in writing a docker image
#######################
## BUILD BASE
# Small image
FROM alpine:3.5
# or
FROM ubuntu:16.04
# LTS
@adis-io
adis-io / README.md
Created May 13, 2022 13:50
How jenkins initializes repo
mkdir <dir>
git init .
git fetch --no-tags --force --progress -- https://github.com/<org>/<repo>.git +refs/heads/<branch>:refs/remotes/origin/<branch>
git config remote.origin.url https://github.com/<org>/<repo>.git
git config --add remote.origin.fetch +refs/heads/<branch>:refs/remotes/origin/<branch>
git config core.sparsecheckout
git checkout -f <sha>
@adis-io
adis-io / remove_nth_node_from_end_of_list.c
Last active January 12, 2022 13:42
Remove Nth Node From End of List #leetcode #c
#include <stdio.h>
#include <stdlib.h>
struct ListNode {
int val;
struct ListNode *next;
};
struct ListNode* createNodeList(int arr[], int numSize);
struct ListNode* removeNthFromEnd(struct ListNode* head, int n);
Authentication: I am who I say I am
Authorization: What am I allowed to do?
@adis-io
adis-io / category.rb
Created September 15, 2020 08:04
Rails models with Wordpress DB
class Category < Taxonomy
def self.sti_name
"category"
end
end
@adis-io
adis-io / README.md
Created May 4, 2020 03:51
How to solve Dry::Struct::Error <attribute> is missing in Hash input

I'm using dry-rb and dry-struct. And I wanted make some attributes optional, but I was confused with optional.

So the thing is, you can't use optional for skipping attributes. Optional means you can pass nil values, that's all.

So if you want to skip attributes, use this attribute by calling attribute?

class User < Dry::Struct
  attribute :name, Types::String
 attribute? :age, Types::Integer
@adis-io
adis-io / README.md
Last active February 28, 2020 15:54
Find tables in postgres with deleted_at column and unique indexes without condition #postgres #query #sql #safe_deletion

So in Postgres you can create partial indexes with condition.
Let's say you have soft deletion in you table and you don't want them to be indexed.

You added deleted_at column, but forget change unique indexes. To find those tables manually will be a bit longer.

Here is SQL query which will help you find them faster:

SELECT tables.table_name
FROM information_schema.tables as tables
INNER JOIN (