Skip to content

Instantly share code, notes, and snippets.

View foliea's full-sized avatar

Adrien Folie foliea

  • Paris, France
View GitHub Profile
@foliea
foliea / page.rb
Last active August 29, 2015 13:59
class Page < ActiveRecord::Base
before_save :parameterize_name
validates :name, uniqueness: { scope: :locale }
validates :name, :locale, presence: true
scope :by_name, lambda { |name| where(name: name) }
def self.get_by_name! name
page ||= self.find_by(name: name, locale: I18n.locale)
class OmniauthProviderDecorator
@@decorations =
{
linkedin: { icon: 'linkedin-square', class: 'primary' },
twitter: { icon: 'twitter-square', class: 'info' },
github: { icon: 'github', class: 'default' },
google_oauth2: { icon: 'google-plus-square', class: 'danger' }
}
def initialize(provider)
@foliea
foliea / main.go
Created June 18, 2014 09:47
A Tour of Go - Equivalent Binary Tree
package main
import "code.google.com/p/go-tour/tree"
import "fmt"
func DoWalk(t *tree.Tree, ch chan int) {
if t.Left != nil {
DoWalk(t.Left, ch)
}
ch <- t.Value
@foliea
foliea / user.rb
Last active August 29, 2015 14:02
Validation fail if trying to remove admin rights to last admin
class User < ActiveRecord::Base
validates :admin, last_stays: true
end
class LastStaysValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
value_was = record.send("#{attribute}_was")
# If last record with attribute was equal to true
# it can't change this attribute value to false
@foliea
foliea / dilemn
Created July 6, 2014 13:58
dilemn.go
param := "stop"
if api.APIVERSION.LessThan("1.14") {
param = "force"
}
var param string
if api.APIVERSION.LessThan("1.14") {
param = "force"
} else {
param = "stop"
@foliea
foliea / timeout
Created July 14, 2014 20:49
timeout
func main() {
cmd := exec.Command(“stuff”)
chan := make(chan int, 1)
go func() {
cmd.Run()
chan <- STOP
}
go func() {
sleep(5)
.ground-button {
@extend .button.secondary;
@include ground-border;
&:hover {
background-color: adjust-color($ground-primary-color, $lightness: -15%)
}
&:focus {
background-color: adjust-color($ground-primary-color, $lightness: -25%)
}
link_to(theme[:label], grounds_switch_editor_theme_path(theme[:code]), method: :patch, remote: true)
match 'grounds/', to: 'grounds#run', as: 'grounds_run', via: :put
match 'grounds/:theme', to: 'grounds#switch_editor_theme', as: 'grounds_switch_editor_theme', via: :patch
Prefix Verb URI Pattern Controller#Action
root GET / grounds#show
grounds_run PUT /grounds(.:format) grounds#run
grounds_switch_editor_theme PATCH /grounds/:theme(.:format) grounds#switch_editor_theme
module CodeEditor
extend self
def use_soft_tabs?
evaluate_script("ground.editor.getSession().getUseSoftTabs();")
end
end