Skip to content

Instantly share code, notes, and snippets.

View biske's full-sized avatar

Ivan Bisevac (Иван Бишевац) biske

View GitHub Profile
git checkout feature1
git rebase master
git push -f origin feature1
psql -U username database_name < sql_file
pry(#<Candidate::ReceptionsController>)> request.query_parameters
=> {"type_of_link"=>"public_link"}
pry(#<Candidate::ReceptionsController>)> request.path_parameters
=> {:controller=>"candidate/receptions", :action=>"show", :id=>"PTALTMUZFNC"}
pry(#<Candidate::ReceptionsController>)> request.request_parameters
=> {}
@biske
biske / time_vs_datatime.md
Created September 28, 2016 11:24 — forked from pixeltrix/time_vs_datatime.md
When should you use DateTime and when should you use Time?

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000
source_config .env.development

Use html_escape for user input when you don't expect html content. For example first_name shouldn't contain html, and you want to escape special html characters like &, ", <, or >.

Use html_safe for fields that has html, but html which is sanitized previously. For example for article body there should be some <p> tags but not <script> ones. So before saving content to database it should be sanitized.

http://stackoverflow.com/a/29206274/507018

@biske
biske / find all except.rb
Created January 27, 2016 13:04
Find all interviews where creator type is Company, and exclude some companies.
Interview.where(creator_type: 'Company').where.not(creator_id: [1, 2, 44]).count
To find Company which name contains Google run:
$ Company.where("name ilike '%Google%'")
Or even better:
$ Company.where("name ilike '%Google%'").pluck(:name)
pg_ctl -D /usr/local/var/postgres stop -s -m fast
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
@biske
biske / postforms.js
Created December 26, 2015 10:27 — forked from adactio/postforms.js
Show a progress bar when a form is submitted (and prevent more than one submission per document).
/*
Show a progress element for any form submission via POST.
Prevent the form element from being submitted twice.
*/
(function (win, doc) {
'use strict';
if (!doc.querySelectorAll || !win.addEventListener) {
// doesn't cut the mustard.
return;
}