This file contains 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
def score(dice) | |
score, values = 0, Hash.new(0) | |
dice.each {|roll_value| values[roll_value] += 1} | |
(2..6).each { |i| score += i*100 if values[i]>=3} | |
return score = score + (values[5] > 3 ? ((values[5]-3)*50) : 0) + (values[1] > 3 ? ((values[1]-3)*100) : 0) + (values[5] < 3 ? (values[5]*50) : 0) + (values[1] >= 3 ? 1000 : values[1]*100) | |
end |
This file contains 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
# Grab your credentials from https://my.slack.com/account/gateways | |
/server add slack yoursubdomain.irc.slack.com/6667 | |
/set irc.server.slack.username yourusername | |
/set irc.server.slack.password yourircpassword | |
/set irc.server.slack.ssl on |
This file contains 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
alias Cooking.User | |
defimpl Canada.Can, for: User do | |
def can?(%User{ id: user_id }, action, %User{ id: user_id }) | |
when action in [:create, :read, :show, :update, :destroy], do: true | |
def can?(%User{ id: user_id }, _, _), do: false | |
end |
This file contains 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
// controllers/home_controller.js | |
var homeController = { | |
index: function(req, res, next) { | |
res.render('index', { title: 'Express', fuck: 'FUCK' }); | |
} | |
} | |
module.exports = homeController; | |
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ |
This file contains 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
var express = require('express'); | |
var router = express.Router(); | |
var homeController = require('controllers/home_controller') | |
/* GET home page. */ | |
router.get('/', homeController.index); | |
module.exports = router; |
This file contains 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
#golf | |
g=[];ARGF.read.chomp.split("\n")[1..-1].each_slice(2){|l,s|l=l.split.map &:to_i;s=s.split.map &:to_i;g<<{n:l[0],k:l[1],s: s}};puts g.map{|t|t[:s].inject(0){|n,q|q<=0?n+1:n}<t[:k]?"YES":"NO"} |
This file contains 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
defmodule Canary.Abilities do | |
defmacro can(user, actions, targets, when: condition) do # This macro throws an error when used | |
quote do | |
defimpl Canada.Can, for: unquote(user).__struct__ do | |
def can?(unquote(user), unquote(actions), unquote(targets)) when unquote(condition), do: true | |
end | |
end | |
end | |
defmacro can2(user, actions, targets, when: condition) do # This macro works |
This file contains 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
defimpl Canada.Can, for: User do | |
def can?(%User{}, :show, %Post), do: true | |
end | |
defimpl Canada.Can, for: User do # this overwrites the first implementation rather than extending it | |
def can?(%User{}, :delete, %Post), do: false | |
end |
This file contains 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
# file1.ex | |
defmodule A do | |
defmacro __using__(_env) do | |
quote do | |
Module.register_attribute __MODULE__, :rules, accumulate: true | |
end | |
end | |
defmacro register() do |
This file contains 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
defmodule Abilities do | |
defmacro __using__(_opts) do | |
quote do | |
Module.register_attribute __MODULE__, :rules, accumulate: true | |
@before_compile unquote(__MODULE__) | |
end | |
end | |
def gather_rules(rules) do | |
rules |
OlderNewer