Skip to content

Instantly share code, notes, and snippets.

View wordcount.go
package main
import (
"strings"
"fmt"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
counter := map[string]int{}
View config.rb
# READS A .yml FILE AND FOR EACH KEY IT WILL CREATE A GETTER AND SETTER METHODS
class Flag
def initialize
@yaml = Psych.load_file('config/flags.yml')
@yaml.each_key do |item|
self.class.send(:define_method, item) { @yaml[item] }
self.class.send(:define_method, "#{item}=") { |value| @yaml[item] = value }
end
end
end
View transaction_cost.rb
class TransactionCost < ActiveRecord::Base
belongs_to :company
belongs_to :app
has_many :range_costs
accepts_nested_attributes_for :range_costs, allow_destroy: true, reject_if: lambda { |a| a[:to].blank? && a[:from].blank? && a[:cost].blank? }
validates :app_id, uniqueness: true
validates :range_costs, presence: true
@gerep
gerep / blogger_foundation_all_fonts.css
Last active Dec 12, 2015
[Blogger] All Foundation icons in one css file.
View blogger_foundation_all_fonts.css
/*
For General Icons: <i class="general foundicon-[icon-name]"></i>
For Social Icons: <i class="social foundicon-[icon-name]"></i>
For Accessibility Icons: <i class="accessibility foundicon-[icon-name]"></i>
For General Enclosed Icons: <i class="enclosed foundicon-[icon-name]"></i>
*/
/* global foundicon styles */
[class*="foundicon-"] {
@gerep
gerep / blogger_foundation.css
Created Feb 13, 2013
[Blogger] Correct Foundation Icon CSS
View blogger_foundation.css
/* font-face */
@font-face {
font-family: "GeneralFoundicons";
src: url("../fonts/general_foundicons.eot");
src: url("../fonts/general_foundicons.eot?#iefix") format("embedded-opentype"), url("../fonts/general_foundicons.woff") format("woff"), url("../fonts/general_foundicons.ttf") format("truetype"), url("../fonts/general_foundicons.svg#GeneralFoundicons") format("svg");
font-weight: normal;
font-style: normal;
}
/* global foundicon styles */
@gerep
gerep / simple_form.rb
Created Feb 19, 2013
[Blogger] CSS Foundation error messages
View simple_form.rb
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
# complete input. You can remove any component from the
# wrapper, change the order or even add your own to the
# stack. The options given below are used to wrap the
# whole input.
config.wrappers :default, :class => :input,
:hint_class => :field_with_hint, :error_class => :error do |b|
## Extensions enabled by default
@gerep
gerep / _form.html.erb
Created Feb 19, 2013
[Blogger] CSS Foundation error messages
View _form.html.erb
<%= simple_form_for @user do |f| %>
<%= f.input :name, label: I18n.t('users.name') %>
<%= f.input :email, label: I18n.t('users.email') %>
<%= f.input :password, label: I18n.t('users.password') %>
<%= f.input :password_confirmation, label: I18n.t('users.password_confirmation') %>
<%= f.input :status, label: I18n.t('users.status') %>
<%= f.button :submit %>
<% end %>
@gerep
gerep / kaprekar.rb
Created Jun 11, 2013
[Blogger] Check if a given number is a kaprekar one
View kaprekar.rb
number = ARGV[0].to_i
size = number.to_s.size
square = (number**2).to_s
first_half = square.size.even? ? square[0..size-1] : square[0..size-2]
second_half = square[-size..-1]
if number == first_half.to_i + second_half.to_i || square.size == 1 && number == square.to_i
@gerep
gerep / page.html
Last active Dec 21, 2015
[Pronatec]
View page.html
<!DOCTYPE html>
<html>
<head>
<title>Indentificadores, classes, css inline</title>
</head>
<body>
<style type="text/css">
/* GENERICAS */
@gerep
gerep / checkout_controller_decorator.rb
Created Sep 8, 2013
[Blogger] Making spree 2.0.3 show your gateway error messages
View checkout_controller_decorator.rb
module Spree
CheckoutController.class_eval do
def update
if @order.update_attributes(object_params)
fire_event('spree.checkout.update')
return if after_update_attributes
unless @order.next
flash[:error] = @order.errors[:base].join("\n")
redirect_to checkout_state_path(@order.state) and return
end