Select all elements in a
that are greater than 5 and multiply them by 2.
Ruby
a.select { |x| x > 5 }.map { |x| x * 2 }
a.find_all { |x| x > 5 }.collect { |x| x * 2 }
a.inject([]) { |b, x| x > 5 ? (b << x * 2) : b }
Select all elements in a
that are greater than 5 and multiply them by 2.
Ruby
a.select { |x| x > 5 }.map { |x| x * 2 }
a.find_all { |x| x > 5 }.collect { |x| x * 2 }
a.inject([]) { |b, x| x > 5 ? (b << x * 2) : b }
# encoding: utf-8 | |
##################################################################################### | |
# | |
# Fetches info about the people you follow on Twitter | |
# and determines who you could/should unfollow based on: | |
# - activity: was their last update more than 3 months ago? | |
# - popularity: do they have less than 25 followers? | |
# - mass following: are they following more than 10000 people? |
#!/usr/bin/env ruby | |
require "fileutils" | |
require "redcarpet" | |
OUTPUT_FOLDER = "html" | |
HTML_TEMPLATE = <<-HTML | |
<!DOCTYPE html> | |
<html> |
def coupon(parts: 4, chars: 4, separator: "-") | |
SecureRandom.hex(parts*chars/2).upcase.scan(%r/.{#{chars}}/).join(separator) | |
end |
module Tree0 { | |
type Tree<T> = Empty | Node<T>; | |
class Empty { | |
public toString(): string { | |
return "Empty"; | |
} | |
} |
#!/bin/bash | |
# Install a custom R version, https://www.r-project.org/ | |
# | |
# Add at least the following environment variables to your project configuration | |
# (otherwise the defaults below will be used). | |
# * R_VERSION | |
# | |
# Include in your builds via | |
# source /dev/stdin <<< "$(curl -sSL https://gist.githubusercontent.com/sklppr/cec1b80642e02a12d4e57bc51d803c2e/raw/089ca9b56d6b2364df29db4e78039c3404ce437f/r.sh)" | |
R_VERSION=${R_VERSION:="3.3.0"} |
module SnakeCase | |
refine String do | |
def snake_case | |
self.gsub(/::/, '/') | |
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2') | |
.gsub(/([a-z\d])([A-Z])/,'\1_\2') | |
.tr("-", "_") | |
.downcase | |
end | |
end |
require "forwardable" | |
module ActiveRecord | |
class Base | |
def save | |
puts "SAVED #{name}" | |
end |