This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class NewCar { | |
// instance variables | |
double start, end, galls; | |
// constructor | |
NewCar(double start) { | |
this.start = start; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!!! 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"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# get all users | |
@users = User.all | |
# get users from given ids | |
ids = [2, 1, 3, 4, 5] | |
@users = User.find(ids) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
( | |
%span{:id => "cart-counter" } | |
= @cart && [email protected]? ? @cart.size : "0" | |
) | |
or | |
(<span id="cart-counter">#{@cart && [email protected]? ? @cart.size : "0"}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |