Skip to content

Instantly share code, notes, and snippets.

@evaldasg
evaldasg / psql-error-fix.md
Created January 14, 2019 17:10 — 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

ZSH_DISABLE_COMPFIX=true to .zshrc rm .zcompdump files from ~/

@evaldasg
evaldasg / GitHub-Forking.md
Created April 30, 2018 09:32 — forked from Chaser324/GitHub-Forking.md
GitHub Standard Fork & Pull Request Workflow

Whether you're trying to give back to the open source community or collaborating on your own projects, knowing how to properly fork and generate pull requests is essential. Unfortunately, it's quite easy to make mistakes or not know what you should do when you're initially learning the process. I know that I certainly had considerable initial trouble with it, and I found a lot of the information on GitHub and around the internet to be rather piecemeal and incomplete - part of the process described here, another there, common hangups in a different place, and so on.

In an attempt to coallate this information for myself and others, this short tutorial is what I've found to be fairly standard procedure for creating a fork, doing your work, issuing a pull request, and merging that pull request back into the original project.

Creating a Fork

Just head over to the GitHub page and click the "Fork" button. It's just that simple. Once you've done that, you can use your favorite git client to clone your repo or j

@evaldasg
evaldasg / wd.rb
Created February 14, 2018 11:25
work days for last 3 months
[26] pry(main)> h
=> [19, 22, 19, 22, 20, 22, 21, 21, 22, 20, 23, 21, 18, 22, 20, 20, 21, 22, 19, 23, 21, 21, 23, 20]
[27] pry(main)> h[0..-3].each_with_index do |e,i|
[27] pry(main)* y = 2018 + (2 + i) / 12
[27] pry(main)* m = (3 + i) % 12
[27] pry(main)* m = m.zero? ? 12 : m
[27] pry(main)* dds = e + h[i+1] + h[i+2]
[27] pry(main)* p ["#{y}-#{m}", dds]
[27] pry(main)* end
["2018-3", 60]
@evaldasg
evaldasg / IdeaVim OS X Key Repeat.markdown
Created January 23, 2018 13:59 — forked from lsd/IdeaVim OS X Key Repeat.markdown
Enable key-repeat for ALL applications or just for IdeaVim/specific JetBrains apps

Upgrading to Lion or Yosemite and WebStorm 9, I noticed key repeat was
turned off for the IdeaVim plugin h j k l keys.

System-wide key repeat

defaults write -g ApplePressAndHoldEnabled -bool false in a terminal will enable
key repeat for every app. This can alternatively be found in the accessibility settings in OS X' preferences.

App specific key repeat

module A
module B
puts "module B inside module A nesting: #{Module.nesting}"
module_function
def show_nesting
puts "show_nesting nesting: #{Module.nesting}"
end
# Fix for:
# fatal: unable to access 'https://github.com/Homebrew/homebrew-core/': LibreSSL SSL_read: error:060BC064:digital envelope
# routines:AEAD_AES_GCM_OPEN:bad decrypt, errno 0
# Error: Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core failed!
`cd "$(brew --repo)" && git fetch`
@evaldasg
evaldasg / gist:61285ab448090a7bbd3d171e116fc831
Created November 23, 2017 12:25 — forked from ryanlecompte/gist:1283413
Providing an ActiveRecord-like before_filter capability to arbitrary Ruby classes
# First the end result of what we want:
class Foo
before_hook :whoa
before_hook :amazing
def test
puts "This is kinda cool!"
end

My largest Sidekiq application had a memory leak and I was able to find and fix it in just few hours spent on analyzing Ruby's heap. In this post I'll show my profiling setup.

As you might know Ruby 2.1 introduced a few great changes to ObjectSpace, so now it's much easier to find a line of code that is allocating too many objects. Here is great post explaining how it's working.

I was too lazy to set up some seeding and run it locally, so I checked that test suite passes when profiling is enabled and pushed debugging to production. Production environment also suited me better since my jobs data can't be fully random generated.

So, in order to profile your worker, add this to your Sidekiq configuration:

if ENV["PROFILE"]
@evaldasg
evaldasg / web-fonts-asset-pipeline.md
Created August 28, 2017 11:50 — forked from anotheruiguy/web-fonts-asset-pipeline.md
Custom Web Fonts and the Rails Asset Pipeline

Web fonts are pretty much all the rage. Using a CDN for font libraries, like TypeKit or Google Fonts, will be a great solution for many projects. For others, this is not an option. Especially when you are creating a custom icon library for your project.

Rails and the asset pipeline are great tools, but Rails has yet to get caught up in the custom web font craze.

As with all things Rails, there is more then one way to skin this cat. There is the recommended way, and then there are the other ways.

The recommended way

Here I will show how to update your Rails project so that you can use the asset pipeline appropriately and resource your files using the common Rails convention.