Skip to content

Instantly share code, notes, and snippets.

package main
import (
"strings"
"fmt"
)
func WordCount(s string) map[string]int {
words := strings.Fields(s)
counter := map[string]int{}
# 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
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 December 12, 2015 12:29
[Blogger] All Foundation icons in one css file.
/*
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 February 13, 2013 13:16
[Blogger] Correct Foundation Icon 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 February 19, 2013 04:53
[Blogger] CSS Foundation error messages
# 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 February 19, 2013 04:55
[Blogger] CSS Foundation error messages
<%= 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 June 11, 2013 17:17
[Blogger] Check if a given number is a kaprekar one
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 December 21, 2015 08:49
[Pronatec]
<!DOCTYPE html>
<html>
<head>
<title>Indentificadores, classes, css inline</title>
</head>
<body>
<style type="text/css">
/* GENERICAS */
@gerep
gerep / checkout_controller_decorator.rb
Created September 8, 2013 20:45
[Blogger] Making spree 2.0.3 show your gateway error messages
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