Skip to content

Instantly share code, notes, and snippets.

View sevenmaxis's full-sized avatar

Serhii Hopkalo sevenmaxis

  • Intetics
  • Ukraine, Kiev
View GitHub Profile
@mankind
mankind / rails-jsonb-queries
Last active April 17, 2024 12:14
Ruby on Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@kekru
kekru / Docker connect to remote server.md
Last active April 15, 2024 16:26
Connect to another host with your docker client, without modifying your local Docker installation

Run commands on remote Docker host

This is how to connect to another host with your docker client, without modifying your local Docker installation or when you don't have a local Docker installation.

Enable Docker Remote API

First be sure to enable the Docker Remote API on the remote host.

This can easily be done with a container.
For HTTP connection use jarkt/docker-remote-api.

@bastman
bastman / docker-cleanup-resources.md
Created March 31, 2016 05:55
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@irisli
irisli / callerName.js
Last active July 18, 2023 14:03
JavaScript get caller in strict mode
"use strict";
var stackTrace = (new Error()).stack; // Only tested in latest FF and Chrome
var callerName = stackTrace.replace(/^Error\s+/, ''); // Sanitize Chrome
callerName = callerName.split("\n")[1]; // 1st item is this, 2nd item is caller
callerName = callerName.replace(/^\s+at Object./, ''); // Sanitize Chrome
callerName = callerName.replace(/ \(.+\)$/, ''); // Sanitize Chrome
callerName = callerName.replace(/\@.+/, ''); // Sanitize Firefox
console.log(callerName)
@burningTyger
burningTyger / 29-prettify.conf
Created December 6, 2014 13:24
Arch better looking fonts for Chrome
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<match target='font' >
<edit mode='assign' name='rgba' >
<const>rgb</const>
</edit>
</match>
<match target='font' >
<edit mode='assign' name='hinting' >
@afolarin
afolarin / docker-log-gist.md
Last active March 16, 2023 13:02
docker-logs
@damien-roche
damien-roche / rubymethodlookup.md
Last active January 16, 2024 10:40
A Primer on Ruby Method Lookup

A Primer on Ruby Method Lookup

Method lookup is a simple affair in most languages without multiple inheritance. You start from the receiver and move up the ancestors chain until you locate the method. Because Ruby allows you to mix in modules and extend singleton classes at runtime, this is an entirely different affair.

I will not build contrived code to exemplify the more complicated aspects of Ruby method lookup, as this will only serve to confuse the matter.

When you pass a message to an object, here is how Ruby finds what method to call:

1. Look within singleton class

@mlanett
mlanett / rails http status codes
Last active May 3, 2024 04:15
HTTP status code symbols for Rails
HTTP status code symbols for Rails
Thanks to Cody Fauser for this list of HTTP responce codes and their Ruby on Rails symbol mappings.
Status Code Symbol
1xx Informational
100 :continue
101 :switching_protocols
102 :processing

Constant lookup in Ruby can happen lexically or through the ancestry tree of the receiver(a class or module). You can identify which lookup rules are being applied by the context you're in or by the syntax being used to define a class or module.

A class body that is defined as class A::B::C; …; end will lookup constants through the ancestry tree when a constant is evaluated in its class body. Anytime you see A::B::C being used as syntax to define a class or lookup the value of a constant the ancestry tree is being used for the lookup.

@renoirb
renoirb / VagrantMultipleMachineWorkspace.md
Last active December 10, 2021 16:53
Using Vagrant with Salty-Vagrant and Multiple virtual machines

Description

Have you ever wanted to have a Vagrant workspace with more than one Virtual Machine, and managed by Salt Stack? I did, but the documentation is not all there yet.

I managed to make it work with the following, hope it will be useful.

To use

See the Complete salty-vagrant setup, but use the current Vagrantfile to have two machines.