Listing posts

Displaying posts 1 - 5 of 338 in total
Rails upgrade notes
mouse 2715 · person cloud · link
Last update
2024-12-05
2024
12-05
«rails notable/interesting changes from v4 to edge»



TODO


Rails 8

1
2
3
4
5
6
7
# importmap + dartsass, NO hotwire
rails new myapp-sass \
  --asset-pipeline=propshaft --css=sass \
  --skip-action-mailbox --skip-action-text \
  --skip-hotwire --skip-jbuilder --skip-test --skip-system-test \
  --skip-bootsnap --skip-brakeman --skip-ci --skip-dev-gems \
  --devcontainer
  • Rails.error.unexpected: report the given error when in production, or raise it when in development (for conditions not supposed to happen)
  • ActiveRecord: rollback a DB transaction with raise ActiveRecord::Rollback
  • ActiveRecord: stop callbacks chain (eg. validation) with throw :abort
  • YJIT enable by default (must be compiled in ruby)
  • Controller.rate_limit
  • .devcontainer folder when creating a new app.
  • default erb PWA files (manifest, service-worker) in app/views/pwa
  • GitHub CI files for Dependabot, Brakeman, RuboCop, and running tests by default (--skip-ci)
  • Brakeman by default for static analysis of security vulnerabilities (--skip-brakeman option)
  • ActiveRecord::Base.with_connection
  • allow_browser


New in rails (till 2019-07-06)

ActiveRecord

ActionView

ActiveJob / background jobs

ActionCable / websockets

Frontend

Email

ActiveStorage / upload to cloud -- guide

Security & Paranoia

Core/config changes

Development

  • rails console --sandbox don't write changes to DB -- PR+cfg
  • byebug > 8.2.1 is faster
  • faster dev reload: set in Gemfile group :development{gem 'listen', '~> 3.0.4'}

Tools / External gems

Testing

Info / Minor changes / Good to know


Upgrade experiences -- google search


References


Tools

  • scaling ruby apps
  • 📺 DHH youtube videos on writing sw well
  • MiniMagick
  • ruby's set: a collection of unordered values with no duplicates
  • obj.method(:method_name).source_location => mostra dov'e' definito il metodo
  • <<~TAG ... TAG al poso di <<-TAG...TAG rimuove gli spazi di indentazione!
  • thor -- build powerful command-line interfaces

Benchmark howto

docs, ips extension, article

1
2
3
4
5
6
7
8
9
require 'benchmark'

a = [:a, :b]
b = :b
n = 10000000
Benchmark.bm do |x|
  x.report { n.times do !(Array(a) & Array(b)).empty? end }
  x.report { n.times do Array(a).include?(b) end }
end
1
2
3
4
5
6
7
8
require 'benchmark/ips' # instructions per second
require 'uri'

uri = 'http://example.com/foos_json?foo=heyo'

Benchmark.ips do |x|
  x.report('URI.parse') { URI.parse(uri) }
end

vedi esempi di barnchmark in Hash#deep_merge PR


Books


~~~ * ~~~

RVM install Ruby with jemalloc and YJIT
mouse 1094 · person cloud · link
Last update
2024-11-25
2024
11-25
« — »

Note: YJIT is only available on arm64 and aarch64.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
apt install rustc           # needed by YJIT
apt install libjemalloc-dev # needed by jemalloc

# install
rvm install ruby-3.3.0 -C --with-jemalloc --enable-yjit

# jemalloc test 1
MALLOC_CONF=stats_print:true rvm 3.3.0 do ruby -e "exit"

# jemalloc test 2
ldd `which ruby` | grep jemalloc
#   => libjemalloc.so.2 => /lib/aarch64-linux-gnu/libjemalloc.so.2

# YJIT test
ruby --yjit -v
#   => ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT [aarch64-linux]

# YJIT lazy loading:
ruby --yjit --yjit-disable -e "... ; RubyVM::YJIT.enable ; ..."

It's also possibile to apply jemalloc to a vanilla ruby:

1
2
# enable and test
LD_PRELOAD="libjemalloc.so.2" MALLOC_CONF=stats_print:true rvm 3.3.0 do ruby -e "exit"

Source: jemalloc @ stackoverflow.com, YJIT docs and RVM howto


~~~ * ~~~

Firefox personalizations attachment
mouse 4391 · person cloud · link
Last update
2024-11-18
2024
11-18
«browser apps/addons/plugins»

Firefox user interface

From mozilla forum:

  1. in about:config set toolkit.legacyUserProfileCustomizations.stylesheets = true
  2. clone & install custom CSS from https://github.com/aris-t2/customcssforfx
  3. uncomment @import "./css/tabs/tabs_below_navigation_toolbar_fx89.css";
  4. cd firefox_profile && rm -rf chrome && ln -sf /path/to/repo/current

My about:config settings

  • browser.download.alwaysOpenPanel = false -- fix naggin download panel since FF 98
  • browser.tabs.loadDivertedInBackground = true @
  • security.dialog_enable_delay = 100 @
  • browser.tabs.hoverPreview.enabled = false @
  • browser.tabs.hoverPreview.showThumbnails = false (Settings>General>Tabs) @
  • set a custom user agent:

    1. Add new string value general.useragent.override
    2. Enter your preferred UA
    3. Check it on https://www.whatsmyua.info/

    This is especially useful if you are on an ARM device (like raspberry pi) and google keeps giving you its mobile version, for example:

    1
    2
    Mozilla/5.0 (X11; Linux armv7l; rv:60.0) Gecko/20100101 Firefox/60.0    # before
    Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0    # after
    

Add-ons

old:


Source: userChrome.org, CustomCSSforFx


~~~ * ~~~

Kobo tools attachment
mouse 1211 · person cloud · link
Last update
2024-11-13
2024
11-13
« — »

Resolutions

  • Sage: 1440x1920
  • Glo: 758x1024

Developer mode / hidden settings

  1. Type devmodeon in the searchbar, search and return to home screen
  2. New menu entry apperars: Settings > Device Information > Developer options
  3. Optional: type devmodeoff to disable it

NickelMenu / quick launcher

  1. Download latest KoboRoot.tgz from home page/github
  2. Connect Kobo to your PC
  3. Put KoboRoot.tgz into KOBOeReader/.kobo
  4. Eject your eReader and wait for it to reboot
  5. Ensure there is a new menu item in the bottom-right main menu entitled NickelMenu
  6. Connect Kobo to your PC again and create a file named KOBOeReader/.adds/nm/config, and follow the instructions in KOBOeReader/.adds/nm/doc to configure NickelMenu

Example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
menu_item :main    :Browser (fullscreen)  :nickel_browser     :
menu_item :main    :Browser (modal)       :nickel_browser     :modal

# KOreader: prevent Kobo from scanning hidden folders on 4.17+
# https://github.com/koreader/koreader/wiki/Installation-on-Kobo-devices#important-notes
# ==> append in ".kobo/Kobo/Kobo eReader.conf":
#   [FeatureSettings]
#   ExcludeSyncFolders=(\\.(?!kobo|adobe).+|([^.][^/]*/)+\\..+)
menu_item :main    :KOReader              :cmd_spawn          :quiet  :exec  /mnt/onboard/.adds/koreader/koreader.sh

menu_item :main    :Plato                 :cmd_spawn          :quiet  :/mnt/onboard/.adds/plato/plato.sh

menu_item :main    :Invert Screen         :nickel_orientation :invert
menu_item :main    :Sudoku                :nickel_extras      :sudoku
#menu_item :main    :Solitaire             :nickel_extras      :solitaire
#menu_item :main    :WordScramble          :nickel_extras      :word_scramble
#menu_item :main    :Dump Syslog           :cmd_spawn          :logread > /mnt/onboard/.adds/syslog.log

menu_item :main    :USB connect           :nickel_misc        :force_usb_connection
menu_item :main    :IP Address            :cmd_output         :500:/sbin/ifconfig | /usr/bin/awk '/inet addr/{print substr($2,6)}'
menu_item :main    :Telnet                :cmd_output         :500:quiet :/usr/bin/pkill -f "^/usr/bin/tcpsvd -E 0.0.0.0 2023"
  chain_success:skip:5
    chain_failure                         :cmd_spawn          :quiet :/bin/mount -t devpts | /bin/grep -q /dev/pts || { /bin/mkdir -p /dev/pts && /bin/mount -t devpts devpts /dev/pts; }
    chain_success                         :cmd_spawn          :quiet :exec /usr/bin/tcpsvd -E 0.0.0.0 2023 /usr/sbin/telnetd -i -l /bin/login
    chain_success                         :dbg_toast          :Started Telnet server on port 2023
    chain_failure                         :dbg_toast          :Error starting Telnet server on port 2023
    chain_always:skip:-1
  chain_success                           :dbg_toast          :Stopped Telnet server on port 2023
menu_item :main    :FTP                   :cmd_spawn          :quiet:/usr/bin/pkill -f "^/usr/bin/tcpsvd -E 0.0.0.0 1021" || true && exec /usr/bin/tcpsvd -E 0.0.0.0 1021 /usr/sbin/ftpd -w -t 30 /mnt/onboard
  chain_success                           :dbg_toast          :Started FTP server on port 1021.

menu_item :main    :Sleep                 :power              :sleep
#menu_item :main    :Reboot                :power              :reboot
menu_item :main    :Power Off             :power              :shutdown

menu_item :library :Import books          :nickel_misc        :rescan_books_full

menu_item :browser :Quit                  :nickel_misc        :home
menu_item :browser :Open modal            :nickel_browser     :modal
menu_item :browser :Invert Screen         :nickel_orientation :invert

menu_item :selection_search :WebSearch    :nickel_browser     :modal:https://duckduckgo.com/?q={1|S|%}

Notes: - FTP: user = root, pass = empty - Telnet: pass = none

KOReader / alternative reader, swiss knife

See the user guide and wiki, then follow install instructions:

  1. Download the latest release from github
  2. Connect Kobo to your PC
  3. unzip -d /path/to/KOBOeReader/.adds/ koreader-kobo-v2023.04.zip
  4. prevent Kobo from scanning hidden folders on 4.17+, append in .kobo/Kobo/Kobo eReader.conf:

    1
    2
    [FeatureSettings]
    ExcludeSyncFolders=(\\.(?!kobo|adobe).+|([^.][^/]*/)+\\..+)
    
  5. add entry in NickelMenu, put in .adds/nm/config:

    1
    menu_item :main :KOReader :cmd_spawn :quiet :exec /mnt/onboard/.adds/koreader/koreader.sh
    
  6. Eject your eReader and enjoy

From the user guide a command to optimize images for the ereader with ImageMagick:

1
2
3
4
5
6
convert input-image.ext \
  -colorspace Lab -filter LanczosSharp -distort Resize 1404x1872 \
  -colorspace sRGB -background white -gravity center -extent 1404x1872! \
  -grayscale Rec709Luminance -colorspace sRGB \
  -dither FloydSteinberg -remap _eink_cmap.gif \
  -quality 75 output-image.ext

_eink_cmap.gif is also attached to this post.

Plato / alternative reader

See the forum thread and NickelMenu entry:

  1. Download the latest release from github
  2. Connect Kobo to your PC
  3. mkdir /path/to/KOBOeReader/.add/plato
  4. unzip -d /path/to/KOBOeReader/.adds/plato/ plato-0.9.36.7z
  5. prevent Kobo from scanning hidden folders on 4.17+, see KOReader instruction above
  6. add entry in NickelMenu, put in .adds/nm/config:

    1
    menu_item :main :Plato :cmd_spawn :quiet :/mnt/onboard/.adds/plato/plato.sh
    
  7. Eject your eReader and enjoy

Misc tools

  • kepubify -- EPUB to KEPUB converter written in Go (standalone executable)

QOL settings

  • full reference

  • enable screenshots by pressing power button (saves a PNG in kobo root dir), append in .kobo/Kobo/Kobo eReader.conf:

    1
    2
    [FeatureSettings]
    Screenshots=true
    
  • auto accept the Computer detected popup when plugged into a computer and enable devmodeon:

    1
    2
    3
    [DeveloperSettings]
    AutoUsbGadget=true
    EnableDebugServices=true
    
  • random screensaver (sleep/poweroff):

    1. put images in .kobo/screensaver
    2. Settings > Energy saving and privacy > check Show current read and Show book covers full screen
  • manual reset procedure: Sage, Glo

Bluetooth page turner

From reddit posts 1, 2:

  1. buy a Ring Remote Control
  2. install https://github.com/tsowell/kobo-btpt
  3. config file .adds/.btpt/D01 Pro:

    1
    2
    nextPage EV_KEY KEY_NEXTSONG 0
    prevPage EV_KEY KEY_PREVIOUSSONG 0
    

~~~ * ~~~

Workplace bad signs
mouse 67 · person cloud · link
Last update
2024-11-13
2024
11-13
« — »

Signs that it's time to quit your job

  1. You're not learning
  2. You have a terrible boss
  3. You're experiencing abuse
  4. Your workplace is a toxic environment
  5. Your feedback and ideas are not heard
  6. You dread going to work in the morning
  7. Your health is being negatively impacted
  8. Your company seems financially unstable
  9. You are being asked to do unethical things
  10. You feel that there is no growth left for you
  11. Your knowledge and skills are under-utilised
  12. You have lost interest or passion for your job
  13. There is a high turnover rate among employees
  14. You get no feedback about your performance
  15. Your responsibilities have increased, but the pay hasn't
  16. You're consistently stressed, negative, or unhappy at work

Signs of a Bad Manager

  1. Micromanagement: Constantly checking in on employees and not allowing autonomy
  2. Poor Communication: Fails to provide clear instructions or feedback
  3. Lack of Empathy: Shows no understanding or concern for employees' personal issues
  4. Takes Credit for Others' Work: Does not acknowledge team contributions
  5. Unapproachable: Creates an environment where employees feel they cannot voice concerns
  6. Inconsistent: Changes decisions frequently and unpredictably
  7. Lacks Vision: Does not have a clear direction or goals for the team
  8. Plays Favorites: Gives preferential treatment to certain employees
  9. Avoids Responsibility: Blames others for their own mistakes
  10. Resists Change: Unwilling to adapt to new ideas or improvements