Skip to content

Instantly share code, notes, and snippets.

if defined?(Rack::Cors)
config.middleware.insert_before 0, Rack::Cors do
allow do
origins 'www.getonbrd.com', 'cludfront-url.net'
resource '*', headers: :any, methods: [:get, :post, :options]
end
end
end
@felipefunes
felipefunes / tsvector_migration.rb
Created October 2, 2019 17:40
TSVECTOR migration for Rails projects
class AddTsvectorColumnToYourModel < ActiveRecord::Migration[5.2]
def up
# 1. Add column to your model
add_column :your_model, :tsv_column_name, :tsvector
# 2. Create index
add_index(:webpros, :tsv_webpros, using: 'gin')
say_with_time("Adding trigger function on webpros for updating tsv_webpros column") do
# 3. Add trigger
execute <<-SQL
# ===== MULTISEARCH ===== #
include PgSearch::Model
multisearchable against: [:attributes, :you, :want, :to, :index]
def search(query)
found_ids = PgSearch.multisearch(query).pluck(:searchable_id)
YourModel.where(id: found_ids)
end
# configure type search options
PgSearch.multisearch_options = {
using: :tsearch
// GOOD! Place the condition inside the Hook
useEffect(() => {
if (posts === null) {
// This will run only if posts are not still fetched.
// If you mount this component more than once,
// the request won't beexecuted again
getPosts();
}
}, []); // Besides, with the empty array this Effect just run once
useEffect(() => {
// Do something
}, []);
// Just the first render every time this component is mounted
useEffect(() => {
// Do something
}, [firstValue, secondValue]);
// "Do something" will be executed
// every time that firstValue OR secondValue change
// because if any value change we are getting a different array
@felipefunes
felipefunes / simple-front-test.html
Last active March 13, 2019 19:21
Simple JavaScript Test
<!DOCTYPE html>
<html>
<head>
<title>Simple JavaScrip Test</title>
</head>
<body>
<div id="app"></div>
<script>
/*
Please put inside the div with id 'app' the last 5 posts (ordered by id)
@felipefunes
felipefunes / gist:5570983
Last active December 17, 2015 07:09
Retina Ready Background Mixin with Compass
// 1.- This mixin works when you add class retina by JavaScript to html tag or when you use media queries
// 2.- This solution works with the sprites of http://compass-style.org/
// 3.- If your retina sprite have a diferente size with your regular sprite you can set the image with the folowing mixin:
$icons-retina: sprite-map("icons-retina/*.png");
@mixin background-retina($file-name) {
background: $icons-retina;
$ypos: round(nth(sprite-position($icons-retina, $file-name), 2) / 2);
background-position: 0 $ypos;