Skip to content

Instantly share code, notes, and snippets.

View theareba's full-sized avatar

Victor Areba theareba

View GitHub Profile
@theareba
theareba / Ruby Crawler
Created April 7, 2015 15:07
Ruby code that crawled some social site, favoriting and commenting on postings among others
#!/usr/bin/ruby
require 'rubygems'
require 'mechanize'
class Bubblews
@rational = Mechanize.new { |agent|
agent.user_agent_alias = 'Windows Mozilla'
}
@theareba
theareba / conversation.rb
Created April 20, 2015 19:33
Ruby and Js codes adapted from my apps
class Conversation < ActiveRecord::Base
belongs_to :sender, :foreign_key => :sender_id, class_name: 'User'
belongs_to :recipient, :foreign_key => :recipient_id, class_name: 'User'
has_many :messages, dependent: :destroy
validates_uniqueness_of :sender_id, :scope => :recipient_id
scope :involving, -> (user) do
where("conversations.sender_id =? OR conversations.recipient_id =?",user.id,user.id)
<!-- Fixed navbar -->
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<%= I18n.locale.eql?(:en) ? link_to("French", 'http://lingualinterrupteur.fr:3000')
: link_to("English", 'http://lingualswitch.en:3000') %>
</button>
<%= link_to "LingualSwitch", root_path, class: "navbar-brand" %>
@theareba
theareba / application.rb
Last active August 29, 2015 14:25
Speed up rails app with model caching tutorials gists
..
module SnippetDemo
class Application < Rails::Application
..
config.cache_store = :redis_store, 'redis://localhost:6379/0/cache', { expires_in: 90.minutes }
..
end
end
@theareba
theareba / Gemfile
Last active September 22, 2015 22:04
source 'https://rubygems.org'
# Specify your gem's dependencies in thetvdb.gemspec
gemspec
gem 'nokogiri'
gem 'rest-client'
class Comment < ApplicationRecord
include Trashable
end
<h3>Client side IP geolocation using <a href="http://ipinfo.io">ipinfo.io</a></h3>
<hr/>
<div id="ip"></div>
<div id="country"></div>
<div id="welcome"></div>
<hr/>Full response: <pre id="details"></pre>
<div id="color-code" style="width: 300px; height: 300px;">
<input type="text" name="color" id="color" class="form-control" placeholder="Enter Color Code or color name">
##### Email Opens:
### Event Test Endpoint:
https://ga-dev-tools.appspot.com/hit-builder/
### Creating GA query properties:
Unique Member ID, Message ID, Message Network & Message Content
From Admin > Custom Definitions > Custom Dimension(order sensitive), create these properties as dimensions(see article https://support.google.com/analytics/answer/2709829)
The resultant properties with the the keys: cd1, cd2, cd3 & cd4. These will be used in the event hit.
User.find_each do |user|
next if user.email == user.email.downcase
user.email = user.email.downcase
user.skip_reconfirmation!
user.save(validate: false)
end
### Contacts Table Migration
class CreateHubspotContacts < ActiveRecord::Migration[5.2]
def change
create_table :hubspot_contacts, id: false do |t|
t.string :contact_id
t.string :first_name,
t.string :last_name,
t.string :email,
t.string :contact_source,
t.string :lifecycle_stage,