Skip to content

Instantly share code, notes, and snippets.

import java.util.Scanner;
class NewCar {
// instance variables
double start, end, galls;
// constructor
NewCar(double start) {
this.start = start;
}
data = [1000,1000,5,1000,4,12,-3,999,0,1000]
# declare and initialize variables for the two largest
max, max_2 = nil, nil
# compute the two largest
data.each_with_index do |n, index|
case
when index == 0
max = n
!!! 5
%html
%head
%meta{:charset => "utf-8"}
%meta{:name => "viewport", :content => "width=device-width, initial-scale=1, maximum-scale=1"}
%title ScheduleMeNow
/ %title= content_for?(:title) ? yield(:title) : "Myapp"
%meta{:content => "", :name => "description"}
%meta{:content => "", :name => "author"}
@tbuehlmann
tbuehlmann / user.rb
Last active December 19, 2015 04:28 — forked from 1dolinski/user.rb
# get all users
@users = User.all
# get users from given ids
ids = [2, 1, 3, 4, 5]
@users = User.find(ids)
#!/usr/bin/env bash
time=1500 # 25 minutes
title="Pomodoro"
icon=/home/yorickpeterse/Pictures/icons/tomato.png
notify-send -i "$icon" "$title" "Starting a new Pomodoro timer"
sleep $time
- player_url = URI.encode('http://'+request.host_with_port + player.url)
- player_title = "AmericanSoccerNow: #{player.title}"
- player_description = player.dek
.detail
.left
- if player.hero_image and player.hero_image.attached
= image_tag player.hero_image.attached.url, :height => 240, :width => 200
%span.imageCaption
= player.hero_image.credit.try(:html_safe)
205356 <pothibo> tbuehlmann: https://gist.github.com/pothibo/6167471
205405 <tbuehlmann> thanks a lot
205453 <pothibo> tbuehlmann: a few assumption here: First you use STL for different User e.g User Admin SuperAdmin, etc. You can retrieve the current_user
205515 <pothibo> my_controller.rb allow for controller level restrictions & per-action
205525 <pothibo> they work in conjunction
@tbuehlmann
tbuehlmann / span.haml
Last active December 26, 2015 07:39 — forked from DriesS/span.haml
(
%span{:id => "cart-counter" }
= @cart && [email protected]? ? @cart.size : "0"
)
or
(<span id="cart-counter">#{@cart && [email protected]? ? @cart.size : "0"})
class RegistrationsController < ApplicationController
before_filter :authenticate_athlete!, :only => [:new, :create]
def new
@race = Race.find(params[:race_id])
@registration = @race.registrations.new
end
def create
@race = Race.find(params[:race_id])
class Ability
include CanCan::Ability
def initialize(user, *args)
super(*args)
alias_action :new, to: :write
alias_action :create, to: :publish
user ||= User.new # guest user (not logged in)
if user.has_role? :admin
can :manage, :all