Skip to content

Instantly share code, notes, and snippets.

View diegodurs's full-sized avatar
💭
Developing the best connected urban e-bike

Diego d'Ursel diegodurs

💭
Developing the best connected urban e-bike
View GitHub Profile
@diegodurs
diegodurs / stateable.rb
Created June 25, 2012 17:30
Ruby stateable lib for ActiveRecord class
# Author: Diego d'Ursel
# ---------------------
#
# This simple lib help you to add state to a model without implementing boring functions for each state
# just add macro like "add_state 1, 'mystate'" to the definition of your ActiveRecord model
# this lib require a "state" field in the model
#
# some example of usage:
# ---------------------
# add_state 0, 'inactive'
@diegodurs
diegodurs / playlist_script.py
Created July 17, 2012 11:13
iTunes Playlist extractor
# FRENCH - POUR LES NULS
# Pour utiliser ce script il vous faut le language de programmation "python" installé sur votre machine (ce qui est d'origine si vous êtes sur MacOS ou un system Unix). Pour windows, il vous faudra l'installer (http://www.python.org/download), ensuite taper dans la console 'path=C:/Python__/' pour pouvoir utiliser directement python à partir de nimporte où.
#
# Utilisation:
# Exporter une playlist d'iTunes en fichier .txt.
# copier coller le script (le fichier .py) dans le dossier ou se trouve votre playlist.
# Ensuite ouvez un terminal et aller dans ce dossier (le commande 'cd' pour change directory vous permet de naviguer dans les dossiers, 'ls' vous affiche le contenu du dossier courant et 'pwd' vous affiche votre emplacement).
# Taper 'python playlist_script.py <votre_fichier.txt>' sans les '<,>' dans le dossier.
import sys
@diegodurs
diegodurs / build_new_rails_app.md
Created September 11, 2012 09:24
Build new Rails App

Generate new app

Don't forget -T -d postgresql. One day create a template and builder

  • rails new AppName -T -d postgresql

Use rspec, haml, coffee, scss

  • rails generate rspec:install In application.rb:

An incomplete cheatsheet for rails 3. Things are added as they are required.

Active Record validations

# http://guides.rubyonrails.org/active_record_validations_callbacks.html

class SomeClass < ActiveRecord::Base

  # emails
@diegodurs
diegodurs / gist:5425232
Last active December 16, 2015 11:09
Fresh install for new computer
- XCode command line tools
- brew # to install the following tools
- rbenv # for ruby versions
- gem, rails # ruby gem, and install rails gem
- postgress # check Postgress.app
- rails/spring preloader / or zeus # preload Rails env
- Better Errors & RailsPanel
- sublime text + sublime-text-2-ruby-tests
- something to use subdomain for development # .pow or something else
- add git origin

Recruiting Web Ninja

require "developer"

People.search_for_role(WebDeveloper).limit(1).who do 
  have(:talent)
  know(:SQL) 
  know(:ruby_on_rails)
 expect { salary }.to be_good
@diegodurs
diegodurs / array_logger.rb
Last active December 27, 2015 01:59
Easy way to keep your debugging logs in a array + outputing to Rails.logger, useful when executing from the console
module ScriptUtils
class ArrayLogger < Array
def initialize(&blk)
@block = if block_given?
blk
else
->(msg){ Rails.logger.info(msg) }
end
end
@diegodurs
diegodurs / rails_resources.md
Created October 31, 2013 13:19 — forked from jookyboi/rails_resources.md
Rails-related Gems and guides to accelerate your web project.

Gems

  • Bundler - Bundler maintains a consistent environment for ruby applications. It tracks an application's code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run.
  • rabl - General ruby templating with json, bson, xml, plist and msgpack support
  • Thin - Very fast and lightweight Ruby web server
  • Unicorn - Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels.
  • SimpleCov - SimpleCov is a code coverage analysis tool for Ruby 1.9.
  • Zeus - Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second.
  • [factory_girl](h
@diegodurs
diegodurs / javascript_resources.md
Created October 31, 2013 13:19 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage
Delayed::Worker.logger = Logger.new(File.join(Rails.root, 'log', 'dj.log'))
Delayed::Worker.logger.info "Debugging job"