Skip to content

Instantly share code, notes, and snippets.

View fervisa's full-sized avatar

Fernando Villalobos fervisa

  • Oaxaca, México
View GitHub Profile
@fervisa
fervisa / queries_2.rb
Created May 14, 2014 18:07
SQL from users/index
# All users (count)
# ======================
SELECT COUNT(DISTINCT "users"."id") FROM "users" LEFT OUTER JOIN "ole_core"."logins" ON "ole_core"."logins"."id" = "users"."login_id" LEFT OUTER JOIN "ole_core"."taggings" ON "ole_core"."taggings"."taggable_id" = "ole_core"."logins"."id" AND ole_core.taggings.context = ('udfs') AND "ole_core"."taggings"."taggable_type" = 'OleCore::Login' LEFT OUTER JOIN "ole_core"."tags" ON "ole_core"."tags"."id" = "ole_core"."taggings"."tag_id" WHERE (logins.account_id = 5359 and (logins.id = 59251 or logins.role >= 6) and users.status != 'Retired' and users.deleted_at is null)
# Filtered users (count)
# ======================
SELECT COUNT(DISTINCT "users"."id") FROM "users" LEFT OUTER JOIN "ole_core"."logins" ON "ole_core"."logins"."id" = "users"."login_id" LEFT OUTER JOIN "ole_core"."taggings" ON "ole_core"."taggings"."taggable_id" = "ole_core"."logins"."id" AND ole_core.taggings.context = ('udfs') AND "ole_core"."taggings"."taggable_type" = 'OleCore::Login' LEFT OUTER JOIN "ol
@fervisa
fervisa / queries-no-ajax.rb
Last active August 29, 2015 14:01
SQL from users/index
# All users (count)
# ======================
SELECT COUNT(DISTINCT "users"."id") FROM "users" LEFT OUTER JOIN "ole_core"."logins" ON "ole_core"."logins"."id" = "users"."login_id" LEFT OUTER JOIN "ole_core"."taggings" ON "ole_core"."taggings"."taggable_id" = "ole_core"."logins"."id" AND ole_core.taggings.context = ('udfs') AND "ole_core"."taggings"."taggable_type" = 'OleCore::Login' LEFT OUTER JOIN "ole_core"."tags" ON "ole_core"."tags"."id" = "ole_core"."taggings"."tag_id" WHERE (logins.account_id = 5359 and (logins.id = 59251 or logins.role >= 6) and users.status != 'Retired' and users.deleted_at is null)
# current subscription x5
# ======================
SELECT "ole_core"."subscriptions".* FROM "ole_core"."subscriptions" WHERE "ole_core"."subscriptions"."deleted_at" IS NULL AND "ole_core"."subscriptions"."account_id" = 5359 LIMIT
# subscription plan
# ======================
@fervisa
fervisa / sanitize.rb
Created May 22, 2014 00:20
Cleaning converted docx -> html file
require 'rubygems'
require 'sanitize'
require 'nokogiri-styles'
no_whitespaces = lambda {|env|
node = env[:node]
return unless node.elem?
unless node.children.any?{|c| !c.text? || c.content.strip.length > 0 }
node.unlink
@fervisa
fervisa / sanitize.rb
Created May 22, 2014 22:50
Ejemplo de transformer
gray_title = lambda do |env|
node = env[:node]
return if !node.elem? or !['p'].member? node.name or !['#D9D9D9', '#E0E0E0'].member? node.styles['background']
node.name = 'h1'
node['class'] = 'gray-title'
node.delete 'style'
node.parent.replace node
return {:node_whitelist => [node]}
end
@fervisa
fervisa / vim_short.md
Last active January 14, 2017 19:05 — forked from apux/1_vim_short.md
mkdir -p ~/.vim/autoload ~/.vim/bundle; \
curl -Sso ~/.vim/autoload/pathogen.vim \
    https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim
set nocompatible
execute pathogen#infect()
syntax on
@fervisa
fervisa / spec_helper.js.coffee
Created July 13, 2014 14:27
specs init for angular backend mocking
#= require application
#= require angular-mocks
#= require support/sinon
#= require support/jasmine-sinon
beforeEach(module('demoApp'))
beforeEach inject (_$httpBackend_, _$compile_, $rootScope, $controller, $location, $injector, $timeout) ->
@scope = $rootScope.$new()
@http = _$httpBackend_
@fervisa
fervisa / angular-csrf-token.coffee
Created July 13, 2014 14:32
Handling Rails csrf-token from an Angular app
demoApp.config ($httpProvider) ->
authToken = $("meta[name=\"csrf-token\"]").attr("content")
$httpProvider.defaults.headers.common["X-CSRF-TOKEN"] = authToken
@fervisa
fervisa / angular-turbolinks.coffee
Created July 13, 2014 14:33
Angular.js: Turbolinks compatibility
@fervisa
fervisa / related-filter.coffee
Created July 13, 2014 15:13
Custom filter to format id based on catalogue
@fervisa
fervisa / vimrc
Created September 16, 2014 19:14
Configuración vim por directorio
set exrc " habilita archivos .vimrc por directorio
set secure " deshabilita comandos inseguros en archivos .vimrc locales