Skip to content

Instantly share code, notes, and snippets.

View bradurani's full-sized avatar

Brad Urani bradurani

View GitHub Profile
@bradurani
bradurani / style.sh
Created October 5, 2021 03:53
Rubocop changed filed
git diff --name-only --diff-filter=AM origin/master | \
xargs bundle exec rubocop --display-cop-names --extra-details --parallel --force-exclusion
@bradurani
bradurani / recursive_threaded_search.rs
Created October 30, 2018 05:39
Recursive Multi-Threaded Mutating Tree Search
use std::thread;
use std::thread::JoinHandle;
use std::sync::{Arc, Mutex, MutexGuard};
type Node = Arc<Mutex<TreeNode>>;
#[derive(Debug)]
struct TreeNode {
value: u16,
children: Vec<Node>,
--lock monitor
CREATE VIEW lock_monitor AS(
SELECT
COALESCE(blockingl.relation::regclass::text,blockingl.locktype) as locked_item,
now() - blockeda.query_start AS waiting_duration, blockeda.pid AS blocked_pid,
blockeda.query as blocked_query, blockedl.mode as blocked_mode,
blockinga.pid AS blocking_pid, blockinga.query as blocking_query,
blockingl.mode as blocking_mode
FROM pg_catalog.pg_locks blockedl
JOIN pg_stat_activity blockeda ON blockedl.pid = blockeda.pid
@bradurani
bradurani / cancel_old_queries.sql
Last active February 19, 2018 17:51
cancel old queries
SELECT
pg_cancel_backend(pid),
now()-pg_stat_activity.query_start AS duration,
query,
state
FROM pg_stat_activity
WHERE (now()-pg_stat_activity.query_start) > interval '1 day';
SELECT pg_sleep(30);
SELECT
pg_terminate_backend(pid),
@bradurani
bradurani / db.bsh
Last active September 5, 2017 04:37
DB management script
#! /usr/bin/env bash
CMD="${1?valid commands are psql, seed, create, drop, reset}"
set -eux pipefail
export $(sed '/^#/ d' .env)
HOST="${DB_HOST-localhost}"
USERNAME="${DB_USERNAME-postgres}"
PASSWORD="${DB_PASSWORD-postgres}"
{
"fromUserName": "Axel Lidenbrock",
"message": "Welcome to the center of the earth",
"chatroom": "foyer"
}
ws.onopen = function () {
if (ws.protocol == 'appProtocol-v2') {
...
} else {
...
}
}
const WebSocket = require('ws');
const server = new WebSocket.Server({ port: 8080 });
server.on('connection', function connection(ws) {
ws.send('connected')
ws.on('message', function incoming(message) {
ws.send('something');
});
var websocket = new WebSocket('ws://echo.websocket.org/');
websocket.onopen = function(e) {
console.log('socket open');
}
websocket.onmessage = function (e){
console.log(e.data)
};
@bradurani
bradurani / blog-migrating-databases-2.rb
Created May 18, 2017 23:32
blog-migrating-databases-2
class AddColumnUsersIsAdmin < ActiveRecord::Migration
phase :pre_restart
def change
add_column :users, :is_admin, :boolean
end
end
class BackfillUsersIsAdminNoLock < ActiveRecord::Migration
phase :post_restart