After modifying an object and after saving to the database, or within after_save
:
Rails <= 5 | Rails >= 5.1 |
---|---|
attribute_changed? | saved_change_to_attribute? |
changed? | saved_changes? |
changes | saved_changes |
attribute_was | attribute_before_last_save |
# If you get "Inappropriate ioctl for device" when decrypting | |
# Thanks to https://github.com/keybase/keybase-issues/issues/2798 | |
export GPG_TTY=$(tty) | |
#!/bin/bash | |
parents_of_dead_kids=$(ps -ef | grep [d]efunct | awk '{print $3}' | sort | uniq | egrep -v '^1$'); echo "$parents_of_dead_kids" | xargs kill |
# From https://github.com/rails/rails/issues/20606#issuecomment-113323102 | |
# Almost good, but I don't think it handles the case of promoting an | |
# existing location to being the primary location correctly in some cases | |
class Organization < ActiveRecord::Base | |
has_many :locations, dependent: :destroy, autosave: true # autosave necessary for the importer | |
has_one :primary_location, -> { where(locations: { primary: true }) }, class_name: "Location", autosave: true | |
# Override getter to fix issue with Rails not reloading the primary_location after resetting it to nil | |
def primary_location |
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") |
module Where | |
class <<self | |
attr_accessor :editor | |
def is_proc(proc) | |
source_location(proc) | |
end | |
def is_method(klass, method_name) | |
source_location(klass.method(method_name)) |
/** | |
* Retrieves all the rows in the active spreadsheet that contain data and logs the | |
* values for each row. | |
* For more information on using the Spreadsheet API, see | |
* https://developers.google.com/apps-script/service_spreadsheet | |
*/ | |
function readRows() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var rows = sheet.getDataRange(); | |
var numRows = rows.getNumRows(); |
-- all connections | |
select pid, datname, usename, left(application_name, 15) as app_name, state, backend_start, xact_start, query_start, state_change, wait_event_type, wait_event, left(regexp_replace(query,E'[\\n\\r]+',' ','g'), 40) from pg_stat_activity WHERE pid<>pg_backend_pid() ORDER BY datname, usename; | |
-- active connections | |
SELECT application_name, state, age(now(), xact_start) age, query FROM pg_stat_activity WHERE state <> 'idle'; | |
SELECT application_name, pid, state, age(now(), xact_start) age, | |
left(regexp_replace(query,E'[\\n\\r]+',' ','g'), 100) | |
FROM pg_stat_activity WHERE state <> 'idle' ORDER BY age; | |
from __future__ import print_function | |
from sqlalchemy import ( | |
Column, | |
create_engine, | |
MetaData, | |
) | |
from sqlalchemy.types import String, Integer | |
from sqlalchemy.dialects.postgresql import UUID | |
from sqlalchemy.orm import sessionmaker | |
from sqlalchemy.ext.declarative import declarative_base |