Skip to content

Instantly share code, notes, and snippets.

View kamalpandey's full-sized avatar
🎯
Focusing

kamalpandey

🎯
Focusing
View GitHub Profile
@kamalpandey
kamalpandey / rails-jsonb-queries
Created June 9, 2022 15:00 — forked from mankind/rails-jsonb-queries
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")
@kamalpandey
kamalpandey / gist.txt
Last active October 4, 2021 05:56
Resolve PG::ConnectionBad: FATAL: password authentication failed for user "postgres"
#go to pg_hba.conf
Add a new line to the top of pg_hba.conf:
local all postgres peer
#go to psql
sudo -u postgres psql
#enter the following command to set or change the password
ALTER USER postgres PASSWORD 'postgres_password';
@kamalpandey
kamalpandey / rails http status codes
Created May 5, 2020 10:15 — forked from mlanett/rails http status codes
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
@kamalpandey
kamalpandey / web-fonts-asset-pipeline.md
Created July 19, 2019 03:30 — 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.

@kamalpandey
kamalpandey / _message.html.erb
Created March 7, 2019 03:49 — forked from Joseph-N/_message.html.erb
Tutorial code snippets for chat application in rails. Tutorial link http://goo.gl/l3e8zN
<li class="<%= self_or_other(message) %>">
<div class="avatar">
<img src="http://placehold.it/50x50" />
</div>
<div class="chatboxmessagecontent">
<p><%= message.body %></p>
<time datetime="<%= message.created_at %>" title="<%= message.created_at.strftime("%d %b %Y at %I:%M%p") %>">
<%= message_interlocutor(message).name %><%= message.created_at.strftime("%H:%M %p") %>
</time>
</div>