Skip to content

Instantly share code, notes, and snippets.

View abelorian's full-sized avatar
🎯
Focusing

Abel O'Rian abelorian

🎯
Focusing
  • Santiago, Chile.
  • 05:12 (UTC -04:00)
View GitHub Profile
@abelorian
abelorian / git_problem.sh
Created January 10, 2017 14:35
git: Your branch and 'origin/master' have diverged - how to throw away local commits?
git fetch origin
git reset --hard origin/master
@abelorian
abelorian / render_to_string.rb
Created January 10, 2017 03:19
Rails js render
def autocomplete
query = params[:q]
@data = SearchService.autocomplete(query)
render text: render_to_string(:action => "partials/_autocomplete.html.erb", :layout => false, data: @data)
end
# $.get( search_autocomplete_url, {q: query}, function(res) {
# $("#search-container").html(res);
# })
# .fail(function() {
@abelorian
abelorian / server_bootstrap.sh
Last active January 8, 2017 01:58
Nuevo Server for Rails 5 on Ubuntu 16.04
# Dependencias
sudo apt-get update
sudo apt-get install build-essential libssl-dev curl libcurl3 libreadline-dev libcurl4-openssl-dev libffi-dev libgdbm3 libgdbm-dev nginx
# Install Java
sudo apt-get install default-jre
# NodeJS
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs
@abelorian
abelorian / pixel.html
Created November 16, 2016 14:28
Facebook BTA pixel
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '869761073129850');
fbq('track', 'PageView');
</script>
# Install dependencies
sudo apt-get install build-essential libssl-dev libreadline-dev zlib1g-dev git curl git-core nginx
# Install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
echo 'export PATH="$HOME/.rbenv/bin:$PATH"'
~/.rbenv/bin/rbenv init
@abelorian
abelorian / fix_encode.rb
Created October 6, 2016 01:27
Paypal PIN and Rails: ActiveRecord::StatementInvalid: PG::CharacterNotInRepertoire: ERROR: invalid byte sequence for encoding "UTF8": 0xf3 0x6e
def paypal_method
transaction_subject = clean_param params[:transaction_subject]
end
def clean_param value
return '' if value.nil?
value.to_s.encode('UTF-8', :invalid => :replace, :undef => :replace)
end
@abelorian
abelorian / search_mongo.rb
Last active September 9, 2016 19:16
Case insensitive search in mongoid + Rails
query = 'Ab'
User.where(name: query) #Exact match
User.where(name: /.*#{query}.*/) # Case sensitive, as LIKE operator
User.where(name: /.*#{query}.*/i) # Case sensitive, as iLIKE operator
# LIKE OR LIKE
User.any_of({first_name: /.*#{query}.*/i}).any_of({ last_name: /.*#{query}.*/i })
# Don`t forget the .to_a method
@abelorian
abelorian / salestream_server.md
Last active September 4, 2016 01:48
Salestream

Instalar

apt-get install -y  build-essential wget zlib1g-dev libssl-dev libffi-dev \
                    libyaml-dev libreadline6 libreadline6-dev libncurses5 \
                    libncurses5-dev libcurl4-openssl-dev mysql-client \
                    libmysqlclient-dev libmagickcore-dev imagemagick \
                    libxml2-dev libxslt1-dev curl git zsh
@abelorian
abelorian / extend_string.rb
Last active March 6, 2023 23:44
Removing Accents In a Ruby String (Updated)
# RemoveAccents version 1.0.3 (c) 2008-2009 Solutions Informatiques Techniconseils inc.
#
# This module adds 2 methods to the string class.
# Up-to-date version and documentation available at:
#
# http://www.techniconseils.ca/en/scripts-remove-accents-ruby.php
#
# This script is available under the following license :
# Creative Commons Attribution-Share Alike 2.5.
#
@abelorian
abelorian / problemas_rails.md
Last active September 22, 2016 20:04
Problemas comunes Rails