There are numerous suggestions, I'm not yet aware of any other collection.
If the list below grows to become useful, someone might like to adapt its content for the FreeBSD wiki.
https://forums.freebsd.org/posts/381779 (2018-03-17)
#!/usr/bin/env zsh | |
# patched versions for CVE-2023-4863: 22.3.24, 24.8.3, 25.8.1, 26.2.1 | |
mdfind "kind:app" 2>/dev/null | sort -u | while read app; | |
do | |
filename="$app/Contents/Frameworks/Electron Framework.framework/Electron Framework" | |
if [[ -f $filename ]]; then | |
echo "App Name: $(basename ${app})" | |
electronVersion=$(strings "$filename" | grep "Chrome/" | grep -i Electron | grep -v '%s' | sort -u | cut -f 3 -d '/') |
class Add | |
attr_reader :result, :is_negative | |
def initialize(a, b) | |
@result = a + b | |
@is_negative = @result < 0 | |
end | |
end | |
def add(a,b) |
There are numerous suggestions, I'm not yet aware of any other collection.
If the list below grows to become useful, someone might like to adapt its content for the FreeBSD wiki.
https://forums.freebsd.org/posts/381779 (2018-03-17)
A userstyle that makes you wait ten seconds before entering a Hacker News thread. I use stylus to manage mine.
.subtext {
display: inline-block;
background: linear-gradient(to left, transparent 50%, #f60 50%) right;
/* bling.js */ | |
window.$ = document.querySelectorAll.bind(document); | |
Node.prototype.on = window.on = function (name, fn) { | |
this.addEventListener(name, fn); | |
} | |
NodeList.prototype.__proto__ = Array.prototype; |
class Coffee | |
attr_accessor :name | |
attr_accessor :strength | |
def initialize(name, strength) | |
@name = name | |
@strength = strength | |
end | |
def <=>(other_coffee) |
@media (min--moz-device-pixel-ratio: 1.5), | |
(-o-min-device-pixel-ratio: 3/2), | |
(-webkit-min-device-pixel-ratio: 1.5), | |
(min-device-pixel-ratio: 1.5), | |
(min-resolution: 144dpi), | |
(min-resolution: 1.5dppx) { | |
/* Retina rules! */ | |
} |
We've seen lots of Ruby feature requests about converting an Enumerable to a Hash: to_h
, map_hash
, map_to
, each_with_hash
, etc. Let's look at one common, simple case of this.
Building a key/value mapping from a collection of keys is awkward. We commonly see Hash[*collection.map { |element| [element, calculate(element)] }]
or collection.each_with_object({}) { |element, hash| hash[element] = calculate(element) }
. Both are verbose. They require boilerplate code that's not relevant to the programmer's intent: to associate an enumerable of keys with calculated values.
Ruby has the idea of an association already: a key and value paired together. It's used by Array#assoc
to look up a value from a list of pairs and by Hash#assoc
to return a key/value pair. Building up a mapping of key/value pairs is associating keys with values.
So! Consider Enumerable#associate
which builds a mapping by associating keys with values:
# Associate filenames with URLs. Before:
# encoding: binary | |
# Removes any bytes from a string that are not valid UTF-8 | |
class Cleaner | |
attr_reader :bytes, :buffer, :outstanding | |
def self.clean(str) | |
new.tap { |c| c << str }.to_s | |
end |