Skip to content

Instantly share code, notes, and snippets.

View leandromarques's full-sized avatar

Leandro Marques leandromarques

  • Eindhoven, NL
View GitHub Profile
class UserSerializer {
constructor(user) {
this.user = user;
}
serialize() {
return (
{
name: this.user.name,
@leandromarques
leandromarques / docker-compose.yml
Last active November 29, 2018 15:47
docker compose
version: '3'
services:
db:
image: postgres
volumes:
- ./tmp/db:/var/lib/postgresql/data
web:
build: .
command: bundle exec rails s -p 3000 -b '0.0.0.0'
volumes:
soubh_old:
adapter: postgresql
database: soubh_v4_portal
username: postgres
password: <%= ENV['SOUBH-BACKEND_OLD_DATABASE_PASSWORD'] %>
host: <%= ENV['SOUBH-BACKEND_OLD_DATABASE_HOST'] %>
@leandromarques
leandromarques / conditional_validation_example.rb
Created July 31, 2018 00:26
Conditional validation example in Rails
validates :datetime_is_not_in_past, if: :datetime_not_nil?
def datetime_is_not_in_past
errors.add(:datetime_field_name, :invalid, message: "cannot be in the past") if self.datetime_field_name < DateTime.current
end
def datetime_not_nil?
!self.datetime_field_name.nil?
end
@leandromarques
leandromarques / pg_config_bundle.sh
Created June 4, 2018 13:48
Command to fix pg gem install in macOS
bundle config build.pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.6/bin/pg_config
@leandromarques
leandromarques / base.rb
Created May 11, 2017 17:52
ajax-datatables-rails Rails 5.1 fix
def sort_records(records)
sort_by = []
params[:order].to_unsafe_h.each do |item|
sort_by << "#{sort_column(item[1]["column"])} #{sort_direction(item[1]["dir"])}"
end
records.order(sort_by.join(", "))
end
def sort_column(item)
class Api::V1::BaseController < ApplicationController
protect_from_forgery with: :null_session
serialization_scope :current_user
include ResourceLoader
include TokenAuthentication
after_action :build_response_headers
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Font-also</title>
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" media="screen" title="no title" charset="utf-8">
<style media="screen">
default: &default
adapter: mysql2
encoding: utf8
pool: 5
username: root
password: root
socket: <%= [
'/var/lib/mysql/mysql.sock',
'/var/run/mysqld/mysqld.sock',
'/tmp/mysqld.sock',
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Summernote1</title>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.css" rel="stylesheet">
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.js"></script>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<script src="//cdn.jsdelivr.net/medium-editor/latest/js/medium-editor.min.js"></script>
<link rel="stylesheet" href="//cdn.jsdelivr.net/medium-editor/latest/css/medium-editor.min.css" type="text/css" media="screen" charset="utf-8">