Skip to content

Instantly share code, notes, and snippets.

@x-yuri
x-yuri / [-command.md
Last active July 1, 2019 07:47
[ command

There exists a way in the shell to do different kinds of checks, like if a file exists:

$ if [ -e some-file ]; then echo exists; fi
exists
@x-yuri
x-yuri / 1.sh
Last active September 15, 2019 09:26
portainer: redeploy stack
#!/usr/bin/env bash
set -eu
portainer=https://example.com
user=name
password=...
endpoint=name
stack=name
auth_resp=$(http POST "$portainer/api/auth" Username="$user" Password="$password")
@x-yuri
x-yuri / index.md
Last active November 21, 2020 12:21
What happens when you get disconnected from a server?

What happens when you get disconnected from a server?

There are basically two modes in which ssh can operate: 1) interactive, 2) non-interactive. These are not official terms. I'm using them here in place of otherwise wordy names like, "an ssh session with an allocated pseudo terminal." To run a command in non-interactive mode you do:

$ ssh host echo test

Interactive mode is entered when you either do:

@x-yuri
x-yuri / index.md
Last active October 7, 2019 13:02
/opt/eff.org/certbot/venv/bin/python: No module named pip.__main__; 'pip' is a package and cannot be directly executed

Debian Wheezy

/opt/eff.org/certbot/venv/bin/python: No module named pip.__main__; 'pip' is a package and cannot be directly executed
Traceback (most recent call last):
  File "/tmp/tmp.Xxcju1yqBr/pipstrap.py", line 177, in <module>
    sys.exit(main())
  File "/tmp/tmp.Xxcju1yqBr/pipstrap.py", line 149, in main
    pip_version = StrictVersion(check_output([python, '-m', 'pip', '--version'])
  File "/usr/lib/python2.7/subprocess.py", line 544, in check_output
@x-yuri
x-yuri / strapi: prefix the endpoints.md
Last active October 15, 2019 18:23
strapi: prefix the endpoints

config/environments/production/custom.json:

{
  "prefixed-router": {
    "enabled": true
  }
}
@x-yuri
x-yuri / rake: FATAL: Listen error: unable to monitor directories for changes.md
Last active October 29, 2019 10:47
rake: FATAL: Listen error: unable to monitor directories for changes.

I was building a docker image. Nothing foretold troubles, but then:

       Step 7/13 : RUN SECRET_KEY_BASE=`bin/rake secret` RAILS_ENV=production         bin/rails assets:precompile
        ---> Running in 51605ddacc67
       FATAL: Listen error: unable to monitor directories for changes.
       Visit https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers for info 
on how to fix this.
@x-yuri
x-yuri / How do I debug bundler.md
Last active October 23, 2019 21:14
How do I debug bundler?

You might have run, or might run in the future (or never run for that mater) into the following issue. Let's do bundle init, create 1.rb:

require 'rubygems'
require 'bundler'
Bundler.setup(:default)

Then add require 'byebug'; debugger to the beginning of the

@x-yuri
x-yuri / Can I require gems that are not part of the bundle.md
Last active October 23, 2019 22:42
Can I require gems that are not part of the bundle?

The straightforward answer is: "You can't." But a more deliberate one would be: "You can't after Bundle.setup has finished executing."

But how does it achieve that? First we've got to clarify a couple of things about rubygems and the require method. The bare require method knows nothing about gems. It requires files, resolving their names (paths indeed) relative to paths from the $LOAD_PATH variable. $LOAD_PATH is not particularly big at the start of an invocation:

@x-yuri
x-yuri / docker-compose-anonymous.yml
Last active April 28, 2024 01:46
docker: migrate volume data #pg #docker
version: '3'
services:
s1:
image: postgres:12
container_name: ${prefix}_compose_anonymous
ports:
- $pg_port:5432
@x-yuri
x-yuri / 1. ruby: list methods (group by class or module).rb
Last active October 25, 2019 13:32
ruby: list methods (group by class/module)
class A
def im; end
def self.cm; end
end
def superclasses c
r = []
while c.superclass
r << c.superclass
c = c.superclass