Skip to content

Instantly share code, notes, and snippets.

🍝
Spaghetting code

Pablo Orellana holamendi

🍝
Spaghetting code
Block or report user

Report or block holamendi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View add_order_units.rb
order_code = 'ABCXXX'
variant_id = 123
variant_units = 3 # unidades a agregar
# encuentra pedido existente
order = shop.order(id: order_code) # si no existe, creamos una nueva
# construimos un array de line_items
# a partir de los items del pedido existente
# si es que la variante que queremos agregar
@matiasleidemer
matiasleidemer / paginate.rb
Last active Jan 8, 2018 — forked from be9/paginate.rb
kaminari + JSON API pagination helper
View paginate.rb
def paginate(scope, default_per_page = 20)
collection = scope.page(params[:page]).per((params[:per_page] || default_per_page).to_i)
current, total, per_page = collection.current_page, collection.total_pages, collection.limit_value
render json: [{
pagination: {
current: current,
previous: (current > 1 ? (current - 1) : nil),
next: (current == total ? nil : (current + 1)),
@javan
javan / direct-uploads.md
Last active Mar 19, 2019
Active Storage direct uploads
View direct-uploads.md
@mankind
mankind / rails-jsonb-queries
Last active Dec 10, 2019
Rails-5 postgresql-9.6 jsonb queries
View rails-jsonb-queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@henrik
henrik / dokku_on_digital_ocean.md
Last active Jul 30, 2019
Notes from running Dokku on Digital Ocean.
View dokku_on_digital_ocean.md

My notes for Dokku on Digital Ocean.

These may be a bit outdated: Since I originally wrote them, I've reinstalled on a newer Dokku and may not have updated every section below.

Commands

Install dokku-cli (gem install dokku-cli) for a more Heroku-like CLI experience (dokku config:set FOO=bar).

# List/run commands when not on Dokku server (assuming a "henroku" ~/.ssh/config alias)
ssh henroku dokku
@colszowka
colszowka / dns_check.rb
Last active Nov 22, 2019
Ruby DNS Check
View dns_check.rb
require 'resolv'
class DnsCheck
attr_reader :host
def initialize(host)
@host = host
end
def a
@a ||= Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::A)
View gist:dc53d8d7034512a995bc

Integrating TinyMCE in an ember-cli app

TinyMCE is a javascript WYSIWYG editor that is highly configurable and has a ton of features and plugins. It integrates with jQuery and, with a bit of work, it can be integrated in your ember-cli app.

Step 1: Install TinyMCE:

bower install --save tinymce

Step 2: Import the required files into your app via broccoli. In order to do that you will need a plugin called broccoli-static-compiler:

@lopezjurip
lopezjurip / gist:a817e96ec833e7667274
Last active Nov 13, 2019
DigitalOcean+Rails+Puma+Dokku+Postgress
View gist:a817e96ec833e7667274
# Based on: http://donpottinger.net/blog/2014/11/17/bye-bye-heroku-hello-dokku.html
# Add to gemfile:
ruby '2.1.2'
gem 'pg'
gem 'puma'
gem 'rails_12factor'
gem 'searchkick'
gem 'typhoeus'
@mihai-scurtu
mihai-scurtu / gist:4a488007cfd150f09a4d
Last active Aug 15, 2018
Integrating TinyMCE in an ember-cli app
View gist:4a488007cfd150f09a4d

Integrating TinyMCE in an ember-cli app

TinyMCE is a javascript WYSIWYG editor that is highly configurable and has a ton of features and plugins. It integrates with jQuery and, with a bit of work, it can be integrated in your ember-cli app.

Step 1: Install TinyMCE:

bower install --save tinymce

Step 2: Import the required files into your app via broccoli. In order to do that you will need a plugin called broccoli-static-compiler:

@joshuapowell
joshuapowell / gist:e209a4dac5c8187ea8ce
Last active Nov 2, 2019
Setup Postgres.app to use PostGIS on OS X
View gist:e209a4dac5c8187ea8ce

Download and Install Postgres.app

Before we can setup PostGIS we need to have a local version of Postgresql installed and running. The most effecient way to do this is to download and install Postgres.app.

Spatially Enable your Postgres Database

Once Postgres.app is installed in your computers /Applications directory. Open the Terminal and enter the following two commands

psql -d DATABASE_NAME -f /Applications/Postgres.app/Contents/Versions/9.3/share/postgresql/contrib/postgis-2.1/postgis.sql
You can’t perform that action at this time.