Skip to content

Instantly share code, notes, and snippets.

@dasibre
dasibre / fluent_calc.rb
Last active August 29, 2015 14:21
Fluent Calculator
#Complex yet elegant
class Calc
{ zero: 0, one: 1, two: 2, three: 3, four: 4, five: 5, six: 6, seven: 7, eight: 8, nine: 9 }.each do |m, n|
define_method("#{m}") { @proc ? @proc.call(n) : (@number ||= n ; self ) }
end
{ plus: :+, minus: :-, times: :*, divided_by: :/ }.each do |m, o|
define_method("#{m}") { @proc ||= lambda { |a| @number.send(o, a) }; self }
end
end
@dasibre
dasibre / app.js
Created June 2, 2015 14:29
Angular Dependency injection]
var myApp = angular.module('myApp', ['myAppController']);
class Ranking
attr_reader :rankings, :current_rank
def initialize
@rankings = [-8, -7, -6, -5, -4, -3, -2, -1, 1, 2, 3, 4, 5, 6, 7, 8]
@rank_index = 0
@current_rank = rankings[@rank_index]
end
def up
return "Already at highest rank" if @rank_index == 15
1 results = []
2 data = File.open("./weather.txt") do |f|
3 lines = f.readlines.drop(2)
4 lines.delete_at(-1)
5 lines.each do |line|
6 temp_hash = Hash.new {|h,k| h[k]={}}
7 day,max,min = line.split(' ')
8 temp_hash[day] = {min:min,max:max}
9 results << temp_hash
10 end
@dasibre
dasibre / polite.rb
Last active September 14, 2015 23:11 — forked from fnando/polite.rb
ActiveRecord macro example
require "active_record"
module Polite
BAD_WORDS = ["fuck", "asshole", "motherfucker", "cunt", "cock", "dickhead"]
ESCAPED = BAD_WORDS.collect {|word| Regexp.escape(word)}
RE = /(#{ESCAPED.join("|")})/i
def self.extended(base)
base.extend ClassMethods
end
@dasibre
dasibre / deployerContextConfig.xml
Created September 21, 2015 16:18
CAS Configuration
<bean id="authenticationManager" class="org.jasig.cas.authentication.PolicyBasedAuthenticationManager">
<constructor-arg>
<map>
<entry key-ref="proxyAuthenticationHandler" value-ref="proxyPrincipalResolver" />
<entry key-ref="primaryAuthenticationHandler" value-ref="primaryPrincipalResolver" />
<entry key-ref="ldapAuthenticationHandler" value-ref="usernamePasswordCredentialsResolver" />
</map>
</constructor-arg>
@dasibre
dasibre / WebDriver_Mocha
Created November 11, 2015 11:34 — forked from patoi/WebDriver_Mocha
Selenium WebDriver JavaScript test with Mocha and NodeJS
/*
* Selenium WebDriver JavaScript test with Mocha and NodeJS
*
* Start with: SELENIUM=PATH_TO_SELENIUM_JAR/selenium-server-standalone-2.31.0.jar mocha -t 10000 -R list google-sample.js
*
* Download selenium-server-standalone-2.31.0.jar from https://selenium.googlecode.com/files/selenium-server-standalone-2.31.0.jar
* 'sudo su' and 'npm install -g colors mocha selenium-webdriver'
*
* http://visionmedia.github.io/mocha/
* https://code.google.com/p/selenium/wiki/WebDriverJs
@dasibre
dasibre / .json
Created November 13, 2015 02:20
users json file
[
{
"gender": "female",
"name": {
"title": "miss",
"first": "mary",
"last": "jones"
},
"email": "mary.jones56@example.com",
"username": "crazypeacock512"
@dasibre
dasibre / concept_data.json
Created February 22, 2016 22:48
concept data paths
{
"type":"concept",
"@id":"http://link.aps.org/cs/concepts/dadb5d96-fc29-4c93-8428-3335c7ad1b2a",
"id":"dadb5d96-fc29-4c93-8428-3335c7ad1b2a",
"legacy_uri":"http://link.aps.org/cs/concepts/dadb5d96-fc29-4c93-8428-3335c7ad1b2a",
"label":"Sound detection",
"uri":"http://physh.aps.org/concept/dadb5d96-fc29-4c93-8428-3335c7ad1b2a",
"paths":[
[
{
@dasibre
dasibre / hash_merge.rb
Created March 4, 2016 15:54
hash merge with block
ids = [%w(d b f a), %w(d c a)]
hash = {}
a.map do |list|
list.each_with_index do |v,idx|
h = {}
h[idx] = v
hash.merge!(h) do |_,left,right|
Array(left) + Array(right)
end
hash