Skip to content

Instantly share code, notes, and snippets.

View goodviber's full-sized avatar

GoodViber goodviber

View GitHub Profile
@goodviber
goodviber / Array to ActiveRecord relation
Created March 9, 2017 11:12
Array to ActiveRecord relation
def job_history
#catch double employee association update
@histories = @job.versions.delete_if { |version| version.changeset.keys[0] == "updated_at" }
#change array to ActiveRecord relation
@histories = @job.versions.where(id: @histories.map(&:id)).paginate(:page => params[:page], :per_page => 15)
end
@goodviber
goodviber / mightysharp survey
Last active May 9, 2017 16:52
survey modelling
# app/models/particiapnt.rb
class Participant < ActiveRecord::Base
belongs_to :country
has_many :answers
has_many :questions, through: :answers
end
# app/models/survey.rb
class Survey < ActiveRecord::Base
has_many :questions
To untrack a single file that has already been added/initialized to your repository, i.e., stop tracking the file but not delete it from your system use: git rm --cached filename
To untrack every file that is now in your .gitignore:
First commit any outstanding code changes, and then, run this command:
git rm -r --cached .
This removes any changed files from the index(staging area), then just run:
git add .
@goodviber
goodviber / gist:d930cc5b549fdb84f06769a94c954c45
Created February 1, 2018 14:51
new local and remote branch
git checkout -b <branch>
Edit files, add and commit. Then push with the -u (short for --set-upstream) option:
git push -u origin <branch>
Git will set up the tracking information during the push.
@goodviber
goodviber / gist:e75e520c46dc704804c2c2c2fa46de3c
Created April 6, 2018 12:10
self evoking switch function in jsx view
<td>
{(() => {
switch(array.od.stage) {
case "Ready To Pick":
return <button
onClick={() => this.handleShow(array.od.id)}
>
Start Picking
</button>;
case "Being Picked":
class Sophead < ApplicationRecord
has_many :ods
has_many :od_items, through: :ods
end
models/od.rb
class Od < ApplicationRecord
belongs_to :sophead
has_many :od_items
end
@goodviber
goodviber / gist:b7b93bc9efc1bf416ee02accc2f69dfd
Created May 30, 2018 08:58
page param for will paginate ajax calls
def edit
if !!(request.referrer[-1] =~ /\A\d+\z/)
@page = request.referrer[-1]
else
@page = 1
end
end
############## form ################
fetch(url,
{
method: 'PUT',
headers: {'Content-Type': 'application/json',
'Accept': 'application/json',
'X-Requested-With': 'XMLHttpRequest',
'X-CSRF-Token': token},
body: JSON.stringify({
"od" : {
"picker_id" : pickerId,
git fetch origin branch:branch
git co branch
@goodviber
goodviber / gist:93fe7cb05d7b023393e9a5ba81341f31
Created July 10, 2018 09:41
Postgres missing connection
trash /usr/local/var/postgres
initdb -D /usr/local/var/postgres/