Skip to content

Instantly share code, notes, and snippets.

View franciscoj's full-sized avatar
🎯
Focusing

Fran Casas franciscoj

🎯
Focusing
View GitHub Profile
@franciscoj
franciscoj / seeds.rb
Created May 12, 2011 10:15
Seed the database using sql files
# db/seeds.rb
Dir.glob("#{base_dir}/*.sql").each do |file_name|
puts "Seeding #{ file_name }"
sql_file = File.new(file_name)
while statements = sql_file.gets("") do
ActiveRecord::Base.connection.execute(statements)
end
end
@franciscoj
franciscoj / sample1.js
Created August 5, 2011 18:17
How to avoid using eval
var property = "property_name";
var object = new Object()
alert(object[property]) //will alert object.property_name
alert(object["property_name"]); //will alert object.property_name
alert(window["object"]["property_name"]) //will alert object.property_name
@franciscoj
franciscoj / simple_form.rb
Created November 2, 2011 16:57
Use twitter bootstrap with simple_form
# config/initializer/simple_form.rb
SimpleForm.setup do |config|
config.hint_class = "hint input"
config.error_class = 'error input'
config.wrapper_class = :clearfix
config.wrapper_error_class = :error
end
@franciscoj
franciscoj / pjson
Last active December 23, 2015 04:08
Pretty pring json from the command line
#!/bin/sh
# Put this file on your ~/bin, give it +x and then run it like:
# curl whatever.jon/it-gives.json | pjson
# It will print a pretty printed version of the josn file.
python -mjson.tool
@franciscoj
franciscoj / .dir-locals.el
Created January 8, 2016 10:01
Configure project to use local eslint (the one in your node-modules)
;; -*- mode: emacs-lisp; -*-
;; It will ask you whether those are safe values when opening a file on the project,
;; type `!` then to make take it as safe values :)
;; Take into account that it will add this as a safe value to your ~/.spacemacs
((nil . ((eval . (progn
(setq flycheck-javascript-eslint-executable
"/path/to/the/project/node_modules/.bin/eslint")
)))))
[Desktop Entry]
Name=Spacemacs
GenericName=Text Editor
Comment=Edit text
MimeType=text/english;text/plain;text/x-makefile;text/x-c++hdr;text/x-c++src;text/x-chdr;text/x-csrc;text/x-java;text/x-moc;text/x-pascal;text/x-tcl;text/x-tex;application/x-shellscript;text/x-c;text/x-c++;
Exec=emacsclient -c %F
Icon=~/.emacs.d/core/banners/img/spacemacs.png
Type=Application
Terminal=false
Categories=Development;TextEditor;
@franciscoj
franciscoj / ivar_vs_reader.md
Last active May 9, 2016 17:27
ivar vs reader

Ruby: ivar vs readers

Spoiler alert: Readers win.

  1. You don't rely on the instance state.
  2. You've better protection againt typos. @ivar might not exist and nothing will fail ivar will complain.
  3. They're easier to mock in specs in case you need to.
  4. They properly wrap the state so that refactors are easier
  5. they can be aliased
  6. they can be alias_method_chained
@franciscoj
franciscoj / reek-flycheck.el
Last active August 22, 2016 09:33
How to see reek analysis on emacs with flycheck.
;; To have reek to smell-check the ruby files
(flycheck-define-checker ruby-reek
"A Ruby smeel checker using reek
See URL `https://github.com/troessner/reek'."
:command ("reek" "--format=xml"
source-original)
:standard-input t
:error-parser flycheck-parse-checkstyle
:modes (enh-ruby-mode ruby-mode)
:next-checkers ((info . ruby-rubocop)))
[Unit]
Description=Emacs daemon
[Service]
Type=forking
ExecStart=/usr/bin/emacs --daemon
ExecStop=/usr/bin/emacsclient --eval "(kill-emacs)"
Restart=always
[Install]
@franciscoj
franciscoj / csv2csv.rb
Created July 24, 2013 08:59
Small ruby script to transform a CSV file into a VCF file.
# Requires fastercsv and vpim gems to be installed
require 'rubygems'
require 'fastercsv'
require 'vpim/vcard'
card = Vpim::DirectoryInfo.create([Vpim::DirectoryInfo::Field.create('VERSION', '2.1')], 'VCARD')
FasterCSV.foreach('contactos.csv') do |row|
first_name = row[1]