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
-- 0. Create a bunch of id => vector results for every definition | |
WITH unnested_keys_as_vector AS ( | |
SELECT id as term_id, to_tsvector((each(definitions)).value) as term | |
FROM glossary_terms | |
WHERE glossary_id = 10 | |
) | |
-- 2. Select the rank so we can sort by it (default order is order of terms in table) | |
SELECT *, ts_rank_cd(term, to_tsquery('I | like | bananas')) as rank | |
FROM glossary_terms | |
-- 1. Join the result of the tsvector search on the terms |
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
use self::DispatchType::{ChangeCurrentChannel, OutgoingMessage, IncomingMessage}; | |
use std::collections::HashMap; | |
use std::sync::{mpsc, Arc, Mutex}; | |
use std::thread; | |
#[derive(PartialEq, Debug, Clone)] | |
enum DispatchType { | |
ChangeCurrentChannel, | |
OutgoingMessage, | |
IncomingMessage |
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 Object | |
def self.measure(method, category_name=nil) | |
alias_method "#{method}_unmeasured", method | |
define_method method do |*args| | |
cat_name = if category_name.respond_to?(:call) | |
# If proc eval in current context and pass args | |
self.instance_exec args, &category_name | |
elsif category_name && category_name.respond_to?(:to_s) | |
# Stringify that thing you gave me | |
category_name.to_s |
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
fn request_temp_code() -> TempCode { | |
Command::new("xdg-open").arg(format!("https://slack.com/oauth/authorize?client_id={}", SLACK_CLIENT_ID)).output().unwrap(); | |
let server = Server::http(Ipv4Addr(127, 0, 0, 1), 9999); | |
let (tx, rx) = channel(); | |
let mtx = Mutex::new(tx); | |
let mut guard = server.listen(move |req: Request, res: Response| { | |
match req.uri { | |
AbsolutePath(path) => { |
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
fn main() { | |
// Command::new("xdg-open").arg("https://slack.com/oauth/authorize?client_id=2334733471.3592055147").output().unwrap(); | |
let server = Server::http(Ipv4Addr(127, 0, 0, 1), 9999); | |
let (tx, rx) = channel(); | |
// tx.send("Test".to_string()); | |
// rx.recv(); | |
let mut _guard = server.listen(move |req: Request, res: Response| { | |
match req.uri { | |
AbsolutePath(path) => { |
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
use std::io::{TcpStream, BufferedWriter}; | |
use std::io::Stream; | |
use std::sync::{RWLock, Arc}; | |
use std::collections::HashMap; | |
pub struct ChatServer<T: 'static + Reader + Writer> { | |
users: Arc<RWLock<HashMap<String, T>>> | |
} | |
// Generics are kinda viral... |
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
config.use_transactional_fixtures = false | |
config.before(:suite) do | |
DatabaseCleaner.clean_with :truncation | |
end | |
config.before(:each) do | |
DatabaseCleaner.strategy = :transaction | |
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
# Hack around the middleware stack a bit to get warden session correctly in | |
config.middleware.delete(ActionDispatch::Cookies) | |
config.middleware.delete(ActionDispatch::Session::CookieStore) | |
config.middleware.insert_before(Rails::Rack::Logger, ActionDispatch::Session::CookieStore) | |
config.middleware.insert_before(ActionDispatch::Session::CookieStore, ActionDispatch::Cookies) | |
# Rotate two files, max 5 mb each | |
config.logger = ActiveSupport::TaggedLogging.new(Logger.new(config.paths['log'].first, 2, 5 * 1024 * 1024)) | |
config.log_tags = [ |
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 Person | |
def self.get_name | |
persons_name | |
end | |
def self.persons_name | |
"Sam" | |
end | |
private_class_method :persons_name |
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 Person | |
def self.get_name | |
persons_name | |
end | |
def self.persons_name | |
"Sam" | |
end | |
private_class_method :persons_name |