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 tappable_id, tappable_type, user_id, created_at, c | |
FROM ( | |
SELECT tappable_id, tappable_type, user_id, created_at, | |
row_number() over(partition by tappable_id order by created_at), | |
count(user_id) over(partition by tappable_id order by created_at) as c | |
FROM taps | |
) as ss | |
WHERE row_number = 1 order by c desc; |
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
typedef struct NDBOX | |
{ | |
int32 vl_len_; /* varlena header (do not touch directly!) */ | |
unsigned int dim; | |
double x[1]; | |
} NDBOX; | |
double | |
similarity(double *a, double *b) | |
{ |
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 temp table mapping as | |
SELECT sr.id as survey_response_id, st.user_id | |
FROM survey_responses AS sr | |
JOIN survey_takings AS st | |
ON st.id = sr.survey_taking_id; | |
create index on mapping (survey_response_id); | |
explain update survey_responses as sr | |
set user_id = mapping.user_id | |
from mapping |
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
rails_dev=# \d sub_scale_scores | |
Table "public.sub_scale_scores" | |
Column | Type | Modifiers | |
--------------+------------------+----------- | |
user_id | integer | not null | |
sub_scale_id | integer | not null | |
average | double precision | | |
Indexes: | |
"sub_scale_scores_pkey" PRIMARY KEY, btree (user_id, sub_scale_id) | |
"index_sub_scale_scores_on_sub_scale_id" btree (sub_scale_id) |
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
\c postgres | |
drop database if exists slowcube; | |
create database slowcube; | |
\c slowcube | |
\timing | |
create schema slowcube; | |
set search_path to slowcube; | |
create extension cube; |
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
rails_dev=# \i neighborcube.sql | |
You are now connected to database "postgres" as user "jay". | |
DROP DATABASE | |
CREATE DATABASE | |
You are now connected to database "jaytest" as user "jay". | |
CREATE SCHEMA | |
SET | |
Timing is on. | |
CREATE EXTENSION | |
Time: 17.912 ms |
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
\c postgres | |
drop database if exists jaytest; | |
create database jaytest; | |
\c jaytest | |
create schema jaytest; | |
set search_path to jaytest; | |
create extension cube; |
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
#!/usr/bin/env ruby | |
# gwssh: ssh via a gateway host. Just use gwssh instead of ssh, | |
# and your options, commands, etc. will be preserved. | |
GATEWAY_HOST = 'gate.example.com' | |
DOMAIN = 'example.com' | |
DEBUG = false | |
OPTIONS_WITH_ARGUMENTS = 'bcDeFiLlmOopRSw' |
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
#!/usr/bin/env ruby | |
# gwssh: ssh via a gateway host | |
# We want to find the hostname so we can add tiptap.com. The hostname will be the | |
# first string in ARGV that isn't a standalone option and that isn't itself the argument | |
# for an option (e.g. in "-F configfile", configfile is not the hostname). | |
# This feels very hacky, and I wonder if there's a more elegant way. |
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 ActiveRecord::Base | |
def self.escape_sql(clause, *rest) | |
self.send(:sanitize_sql_array, rest.empty? ? clause : ([clause] + rest)) | |
end | |
def self.execute_sql(conditions, *rest) | |
self.connection.execute(escape_sql(conditions, *rest)) | |
end | |
end |