Listing posts

Displaying posts 286 - 290 of 328 in total
Ruby | All exceptions list
mouse 1620 · person cloud · link
Last update
2017-05-09
2017
05-09
« — »
1
2
3
4
ObjectSpace.
  each_object(Class).
  map{|k| k.to_s if k.ancestors.include?(Exception) }.
  compact.sort

Source: StackOverflow


~~~ * ~~~

Gestione overlay schermo Samsung
mouse 1808 · person cloud · link
Last update
2017-05-06
2017
05-06
« — »

Ecco dove trovare la maledetta sezione per gestire la fastidiosa opzione overlay schermo che spesso crea problemi con Android installato sui stramaledetti Samgung:

  1. Impostazioni
  2. Gestione applicazioni
  3. Menu: Le applicazioni che possono venire visualizzate i...

Fonte: AndroidWorld


~~~ * ~~~

Systemd | Do not clear tty console
mouse 2034 · person cloud · link
Last update
2017-05-04
2017
05-04
«systemctl/journalctl logging»
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# show all getty services
systemctl -a | grep getty.*service

# inspect the one we are interested in:
systemctl cat getty@tty1.service
# and note that the VT is cleared by TTYVTDisallocate=yes

# turn this off for all tty by adding a config file:
mkdir /etc/systemd/system/getty@.service.d
echo -en "[Service]\nTTYVTDisallocate=no" > \
  /etc/systemd/system/getty@.service.d/noclear.conf

systemctl daemon-reload # reload units

# reinspect the file and look at the bottom for your changes:
systemctl cat getty@tty1.service

# reboot and enjoy!

Note: You can always see all boot messages with the journalctl command.


Source: Wooledge wiki


~~~ * ~~~

Rails ActiveSupport Concerns
mouse 1790 · person cloud · link
Last update
2017-04-11
2017
04-11
« — »

Put this template in your /app/(models|controllers)/concerns folder:

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
# /app/(models|controllers)/concerns/my_module.rb
module MyModule
  extend ActiveSupport::Concern

  included do
    scope :disabled, -> { where(disabled: true) }
    before_save :my_instance method
    ...
  end

  # use this syntax with Rails 5
  class_methods do
    def my_class_method
      ...
    end
  end # class_methods

  # use this syntax with Rails 4
  module ClassMethods
    def my_class_method
      ...
    end
  end # module ClassMethods

  def my_instance_method
    ...
  end
end

Then load it in your model/controller:

1
2
3
4
5
6
7
class MyModel < ActiveRecord::Base
  include MyModule
end

class MyController < ApplicationController
  include MyModule
end

NOTE: for Rails < 4 remember to configure autoload_paths in /config/application.rb like this:

1
2
3
4
5
6
7
8
module MyAppName 
  class Application < Rails::Application
    # Custom directories with classes and modules you want to be autoloadable.
    # config.autoload_paths += %W(#{config.root}/extras)
    config.autoload_paths << Rails.root.join('app', 'models'     , "concerns")
    config.autoload_paths << Rails.root.join('app', 'controllers', "concerns")
  end
end

WARNING: Moldel and controller concerns have the same scope! If you define two files with the same name but different path (eg: /app/models/my_module.rb and /app/controllers/my_module.rb) they will clash and only the last one loaded will be used.


Sources: DHH, Rails Api, StackOverflow


~~~ * ~~~

Animated GIF to MP4 video conversion
mouse 1977 · person cloud · link
Last update
2017-04-07
2017
04-07
« — »
1
2
3
4
5
6
# make a video for PCs:
ffmpeg -i in.gif -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" out.mp4

# make a video optimized for Browsers:
ffmpeg -i in.gif -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" \
  -movflags faststart -pix_fmt yuv420p out.mp4

Options:

  • -vf "...": ensure that both dimensions are divisible by 2 in order to have a valid MP4 file.
  • -movflags: optimize browser file loading time.
  • -pix_fmt yuv420p (chroma subsampling): set a high compatibility pixel format for all browsers.

Source: Rigor.com