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
# Other syntax without patch | |
STUDENT_LEVELS = { | |
freshman: Student::Underclassman, | |
sophomore: Student::Underclassman, | |
junior: Student::Upperclassman, | |
senior: Student::Upperclassman, | |
graduate: Student::Graduate | |
}.tap { |h| h.default = Student::Unregistered } | |
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
STUDENT_LEVELS = Hash.new(Student::Unregistered).merge( | |
freshman: Student::Underclassman, | |
sophomore: Student::Underclassman, | |
junior: Student::Upperclassman, | |
senior: Student::Upperclassman, | |
graduate: Student::Graduate | |
) | |
klass = STUDENT_LEVELS[params[:student_level]] | |
student = klass.new(name, birthdate, address, phone) |
Search for password entropy
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 decisionnode: | |
def __init__(self,col=-1,value=None,results=None,tb=None,fb=None): | |
self.col=col # column index of criteria being tested | |
self.value=value # vlaue necessary to get a true result | |
self.results=results # dict of results for a branch, None for everything except endpoints | |
self.tb=tb # true decision nodes | |
self.fb=fb # false decision nodes | |
# Divides a set on a specific column. Can handle numeric or nominal values |
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 re | |
from math import log,pow | |
class PasswordStrength: | |
def __init__(self): | |
self.numeric=re.compile('\d') | |
self.loweralpha=re.compile('[a-z]') | |
self.upperalpha=re.compile('[A-Z]') | |
self.symbols=re.compile('[-_.:,;<>?"#$%&/()!@~]') | |
self.num_of_symbols=20 # adjust accordingly... |
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
def count_nodes(label) | |
before = ObjectSpace.count_objects | |
yield | |
after = ObjectSpace.count_objects | |
puts " #{label} created T_NODE: %d" % (after[:T_NODE] - before[:T_NODE]) | |
end | |
class MyClass | |
include Enumerable |
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
defmodule ExUnit.Lets do | |
defmacro __using__([]) do | |
quote do | |
import ExUnit.Lets | |
end | |
end | |
defmacro let(name, expr) do | |
if match?([do: _], expr) do | |
expr = expr[:do] |
See https://www.youtube.com/watch?v=4_RJu_TrqO0&feature=youtu.be&t=8h6m40s
$ ruby dilute.rb fib.rb
def fi n
if n < 3
1
else
fib(n-1 + ib(n
end