Skip to content

Instantly share code, notes, and snippets.

@crova
crova / phonetique-ca.ex
Created February 16, 2021 15:06
Crawly Spider
defmodule RampeFle.PhonetiqueCa do
use Crawly.Spider
@impl Crawly.Spider
#def base_url(), do: "http://www.phonetique.ca"
@base_url "http://www.phonetique.ca"
@impl Crawly.Spider
def init() do
@crova
crova / snippet.js
Last active August 14, 2018 17:33
Image gets 'clicked' when page loads without any action
<script>
// starts to use what we got stored
var obj = getCookie();
//img swap snippet below
var img = document.querySelectorAll("img.elIMG")[1];
var img_href = document.querySelectorAll("img.elIMG")[1].dataset.imagelink;
// Starts to generate new img url based on cookie data
var new_img_href = img_href.replace(/#prod_geo#/g,obj.prod_geo).replace(/#prod_name#/g,obj.prod_name).replace(/#subprod_name#/g,obj.subprod_name).replace(/#offer_name#/g,obj.offer_name).replace(/#offer_device#/g,obj.offer_device);
// Add listener on image. Swap parameters on the image url query string if it is clicked!
@crova
crova / query string parameters swapper.js
Created July 13, 2018 11:31
can't replace image url
<script>
// starts to use what we got stored | gets button
var obj = getCookie();
var button = document.querySelectorAll("a.elButton");
// dsk button
var my_btn = button[0];
href = my_btn.href;
href = href.replace(/#prod_geo#/g,obj.prod_geo);
href = href.replace(/#prod_name#/g,obj.prod_name);
href = href.replace(/#subprod_name#/g,obj.subprod_name);
@crova
crova / get and use cooki.js
Last active July 9, 2018 19:25
how to get info pro cookie
<script>
document.cookie;
function getCookie(Munchmothafuckincookies) {
var s1 = s1 + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
@crova
crova / change_href.js
Created July 9, 2018 17:44
How can one achieve the same thing using Cookies to pass along the "aff_sub"?
<script>
$(document).ready(function () {
$(window).load(function () {
if (getURLParameter("aff_sub") != "null") {
var href = $("a[href*='#aff_sub#']").attr("href");
href = href.replace(/#aff_sub#/g,getURLParameter("aff_sub"));
$("a[href*='#aff_sub#']").attr("href",href);
}
});
});
@crova
crova / replace href.js (dont work)
Created July 9, 2018 14:03
trying to replace href
<script>
$(function () {
var terms = {
"email": { //set your term name
"default": "" //set your default value
}, //don't forget commas to separate terms
"aff_sub": {
"default": "not given"
}
};
@crova
crova / _form.html.erb
Created April 5, 2018 19:40
Getting undefined method 'map' for Nil Class (coming from Kind.all on the select_options method)
<%= form_for(@contact, html: { class: "basic-grey" }) do |f| %>
<% if @contact.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@contact.errors.count, "error") %> prohibited this contact from being saved:</h2>
<ul>
<% @contact.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
@crova
crova / Assumption
Created January 21, 2018 21:46
Any idea on how to create a scope with OR to select more than one 'source'?
By the serve log I can see that there is no 'OR' on the search query. How can one add it for my scope under the model?
@crova
crova / application.js
Created January 18, 2018 17:34
Dropdowns don't work
// This is a manifest file that'll be compiled into application.js, which will include all the files
// listed below.
//
// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
//
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
// compiled file. JavaScript code in this file should be added after the last require_* statement.
//
// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
@crova
crova / ActiveRecord::StatementInvalid in DbCampaignsController#index
Last active January 17, 2018 14:47
Getting undefined column with PG_Search + Filterrific query
PG::UndefinedColumn: ERROR: column db_campaigns.partner, does not exist LINE 1: ...(ts_rank((to_tsvector('simple', unaccent(coalesce("db_campai... ^ HINT: Perhaps you meant to reference the column "db_campaigns.partner" or the column "db_campaigns.partner". : SELECT SUM("db_campaigns"."sent") FROM "db_campaigns" INNER JOIN (SELECT "db_campaigns"."id" AS pg_search_id, (ts_rank((to_tsvector('simple', unaccent(coalesce("db_campaigns"."partner,"::text, ''))) || to_tsvector('simple', unaccent(coalesce("db_campaigns"."name,"::text, ''))) || to_tsvector('simple', unaccent(coalesce("db_campaigns"."segment,"::text, ''))) || to_tsvector('simple', unaccent(coalesce("db_campaigns"."theme,"::text, ''))) || to_tsvector('simple', unaccent(coalesce("db_campaigns"."database"::text, '')))), (to_tsquery('simple', ''' ' || unaccent('residencial') || ' ''')), 0)) AS rank FROM "db_campaigns" WHERE (((to_tsvector('simple', unaccent(coalesce("db_campaigns"."partner,"::text, ''))) || to_tsvector('simple', unaccent(coalesce("db_campai