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 a group | |
CREATE ROLE readaccess; | |
-- Grant access to existing tables | |
GRANT USAGE ON SCHEMA public TO readaccess; | |
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess; | |
-- Grant access to future tables | |
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO readaccess; |
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
-- list row counts | |
SELECT schemaname,relname,n_live_tup | |
FROM pg_stat_user_tables | |
ORDER BY n_live_tup DESC; | |
-- see vacuum records | |
SELECT | |
schemaname, relname, | |
last_vacuum, last_autovacuum, |
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
import React, { Component } from 'react'; | |
import logo from './logo.svg'; | |
import './App.css'; | |
const SITE_KEY = 'xxxx' | |
class ReCAPTCHA extends Component { | |
constructor(props) { | |
super(props) | |
this._execute = this._execute.bind(this) |
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
# with pool size = 2 | |
def query thread_idx | |
p "#{thread_idx}: in thread" | |
p "#{thread_idx}: conn id: #{ActiveRecord::Base.connection.object_id}" | |
p "#{thread_idx}: #{User.count}" | |
puts "#{thread_idx}: finish query" | |
sleep 0.5 | |
puts "#{thread_idx}: end thread" | |
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
class AddRandomIdGenerator < ActiveRecord::Migration | |
# ref: http://www.rightbrainnetworks.com/blog/base36-conversion-in-postgresql/ | |
# ref: http://rob.conery.io/2014/05/29/a-better-id-generator-for-postgresql/ | |
def up | |
func_sql = <<-SQL | |
CREATE OR REPLACE FUNCTION base36_encode(IN digits bigint, IN min_width int = 0) | |
RETURNS varchar AS $$ | |
DECLARE | |
chars char[]; | |
ret varchar; |
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
# add foreign key constraint | |
execute <<-SQL | |
alter table access_tokens | |
add constraint fk_access_token_user_id | |
foreign key (user_id) | |
references users(id) | |
on delete cascade | |
SQL | |
# add unique index |
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 Ajax { | |
static respondTo(request, resHash, code = 200) { | |
request.respond(code, | |
{ 'Content-Type': 'application/json' }, | |
JSON.stringify(resHash)); | |
} | |
constructor() { | |
this._ajax = sinon.useFakeXMLHttpRequest(); | |
let requests = this.requests = []; |
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
#!/bin/sh | |
### | |
# Strip whitespaces and convert to Unix newlines. | |
# Source: http://stackoverflow.com/a/3516525/86294 | |
# Save this file into git config directory as .git/hooks/pre-commit | |
### | |
if git-rev-parse --verify HEAD >/dev/null 2>&1 ; then | |
against=HEAD | |
else |
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
$buttons2x-sprites: sprite-map('buttons2x/*.png'); | |
%buttons2x-sprite { | |
background-image: sprite-url($buttons2x-sprites); | |
} | |
@mixin buttons2x-sprite($sprite-name){ | |
@extend %buttons2x-sprite; | |
background-repeat: no-repeat; |
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
# Usage: | |
# include_examples 'require_in_params', :tag, ->(group) { post :create, params } | |
shared_examples "require_in_params" do |attr, block| | |
it "returns 400 if no `#{attr}` in params" do | |
params.delete attr | |
self.instance_eval &block | |
expect(response.status).to eq(400) | |
end | |
end |
NewerOlder