This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Postgress --- | |
--------- | |
1. Terminate open connection except mine. | |
SELECT pg_terminate_backend(pg_stat_activity.pid), pg_stat_activity.pid, pg_stat_activity.client_addr, pg_stat_activity.application_name, pg_stat_activity.usename | |
FROM pg_stat_activity | |
WHERE datname = current_database() | |
AND pid <> pg_backend_pid(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Orion::Api::V1::Event.where(id: []) | |
Orion::Api::V1::Event Load (36.5ms) SELECT "events".* FROM "events" WHERE "events"."deleted_at" IS NULL AND 1=0 | |
=> [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE OR REPLACE FUNCTION trigger_set_timestamp() | |
RETURNS TRIGGER AS $$ | |
BEGIN | |
NEW.updated_at = NOW(); | |
RETURN NEW; | |
END; | |
$$ LANGUAGE plpgsql; | |
create table users ( | |
id SERIAL PRIMARY KEY NOT NULL, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jjacob~/Code/netflix/orion_api/src $ cat config/initializers/my_per_logger.rb | |
class InstrumentationLogger | |
MAX_DURATION = 3.0 | |
def self.initialize! | |
ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start, finish, id, payload| | |
duration =( (finish.to_f - start.to_f) * 1000).round(2) | |
Rails.logger.info("slow query detected: #{payload[:name]}, duration: #{duration}") | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# you have ctags but it does not work... | |
$ ctags -R --exclude=.git --exclude=log * | |
ctags: illegal option -- R | |
usage: ctags [-BFadtuwvx] [-f tagsfile] file ... | |
#you need to get new ctags | |
$ brew install ctags | |
#alias ctags if you used homebrew | |
$ alias ctags="`brew --prefix`/bin/ctags" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trackers: computed('model.isLoaded',{ | |
get(key) { | |
if (get(this, 'model.isLoaded')) { | |
get(this, 'store').query('tracker', {'kid_id' : get(this, 'model').get('id')}).then((trackers) => | |
return set(this, 'trackers', trackers); | |
}); | |
} | |
return null; | |
}, | |
set(key, value) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find ./ -type f \( -name "*.erb" -o -name "*.rb" -o -name "*.js" \) -exec grep -H "searchstring" {} \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select pg_terminate_backend(pid) from pg_stat_activity where datname='dbname' | |
assuming all the sessions have to be terminated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def recursive_stringify_keys! | |
self.each do |key, value| | |
string_key = key.to_s | |
unless key.is_a?(String) | |
self[string_key] = self[key] | |
self.delete(key) | |
if self[string_key].is_a?(Hash) | |
self[string_key] = self[key.to_s].recursive_stringify_keys! | |
elsif self[string_key].is_a?(Array) #this can be extended to any collection, reverted back because String had :each ! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Webrat | |
class Scope | |
def update_form_attr(id, action) | |
ele = FormLocator.new(@session, dom, id).locate | |
ele.update({'action' => action}) | |
end | |
end | |
class Form < Element #:nodoc: | |
def update(attr_hash = {}) |