...middleware yourself. Here is an example that limits concurrency of the "mailers" queue to 1. It uses a database mutex via the with_advisory_lock gem but you could easily...
...rand(4)}" (not perfect, but might be good enough). For rate-limiting (e.g. only 1 job per 5 seconds) you could name it "mailers-throttle-#{(Time.now.to_i / 5.0).to_i...
...a makandra card?") }; let cardsPathPattern = /(\/[\w-]+\/\d+)-.+/; if (window.location.pathname.match(cardsPathPattern)) { let currentPath = window.location.pathname.match(cardsPathPattern)[1]; let title = document.querySelector('h1.note--title')?.textContent; if (title) { prompt("Your markdown link:", `[${title}](${currentPath})`);
Typhoeus has a different way of representing array params in a get request than RestClient. Typhoeus: http://example.com/?foo[0]=1&foo[1]=2&foo[2]=3
Trick: Do not use convert but mogrify: mogrify -resize 50% * This overwrites the original image file. In contrast, convert writes...
...circle, it is then asked to compute the arc cosine of a result like 1.0000000001. Since this is undefined, MySQL correctly returns NULL (instead of the expected distance of...
...this problem is to discard rounding errors by forcing any results into bounds [-1; 1] before computing the arc cosine on it. Put the following into an initializer like config/initializers/graticule_spherical_to_sql_without_nulls.rb...
We forked trusty memoizer to make two changes: Memoized methods now preserve their arity. Previously all memoized methods had an...
...you should still remove them after you're done. Here are three options: Option 1: Using a block it 'does something with a temporary directory' do Dir.mktmpdir('exports') do |export...
...event listener with { once: true }: up.on('up:fragment:inserted', { once: true }, function () {...
In Unpoly 1 you can immediately unregister the listener with up.off: up.on('up:fragment:inserted', function fragmentInsertedCallback() {
...was not detected in the system." $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" exit 1 end end Deploying again should now install the missing dependencies as expected...
...unexpectedly splat the array elements: block = proc { |a, b| "a=#{a}, b=#{b}" } block.call(1, 2) # "a=1, b=2" block.call([1, 2]) # "a=1, b=2" Note that lambdas...
...behave as expected: block = lambda { |a, b| "a=#{a}, b=#{b}" } block.call(1, 2) # "a=1, b=2" block.call([1, 2]) # ArgumentError: wrong number of arguments (1 for...
...Let's say you split User into the traits "authentication" and "permissions". In Modularity 1 you now had to say: class User < ActiveRecord::Base does 'user/authentication' does 'user/permissions' end
Automatically migrate a project to Modularity 2 If you have been using Modularity 1 with the does syntax, the Modularity 2 gem provides a script to migrate your Ruby...
...always cached prior to actually storing it (to support form roundtrips). Carrierwave by default 1) copies the file to the cache and then 2) copies it again to its final...
Icon font: little CPU load (no JavaScript) fonts are relatively large 1 extra HTTP request Javascript + inline SVG: higher CPU load (needs to watch the DOM via...
no extra HTTP requests SVG sprites: largest file size, hard to subset 1 extra HTTP request In practice there are probably additional performance tradeoffs. Luckily, there is a...
...projects, :analytic_stats, :jsonb) Project.reset_column_information Project.find_each do |project| project.analytic_stats = { version: 1, analytics_url: nil, clicks_this_week: 0, clicks_this_month: 0, clicks_this_year...
...ApplicationRecord validate :validate_analytic_stats_against_json_schema has_defaults( analytic_stats: proc { { version: 1, analytics_url: nil, clicks_this_week: 0, clicks_this_month: 0, clicks_this_year...
...application, you can use these few lines of CoffeeScript code: joinSentence = (array) -> if array.length > 1 array[0..-2].join(', ') + ', and ' + array[-1..] else array.join ', ' Examples: > joinSentence(['cats', 'dogs', 'pandas'])
...Here is some plain JavaScript, should you prefer that: function joinSentence(array) { if (array.length > 1) { return array.slice(0, -1).join(', ') + ', and ' + array.slice(-1); } else { return array.join...
...threads. Unfortunately, when you use blocking system calls (e.g. locks on the database), Ruby 1.8 threads won't work because system calls will block the whole interpreter. Luckily you can...
...ActiveRecord::Base.establish_connection(config) end it 'should synchronize processes on the same lock' do (1..20).each do |i| fork_with_new_connection do @reader.close ActiveRecord::Base.connection.reconnect! Lock.acquire('lock') do...
...closure-like entities? "return" returns from closure True closure? or declaring context...? Arity check? --------------- ----------------------------- ------------------- 1. block (called with yield) N declaring no 2. block (&b => f(&b) => yield) N declaring...
...Y except return declaring warn on too few 5. proc <<< alias for lambda in 1.8, Proc.new in 1.9 >>> 6. lambda Y closure yes, except arity 1 7. method Y closure...
:T_MODULE=>44, :T_FLOAT=>4, :T_STRING=>65685, :T_REGEXP=>137, :T_ARRAY=>984, :T_HASH=>87, :T_STRUCT=>12, :T_BIGNUM=>2,
:T_COMPLEX=>1, :T_SYMBOL=>29, :T_IMEMO=>5008, :T_ICLASS=>49} Look out for a number that keeps growing over time. Rails In a Rails application...
...to read a cookie's value, you need to parse the string: document.cookie.match(/hello=([^;]+)/)[1] // => "universe" Set a cookie Setting cookies works as simple as this: document.cookie = "yes=please"
...for can be set as part of the string: document.cookie = "yes=please; expires=Sun, 1 May 2016 13:37:00 UTC; path=/" Important: If you do not set a path...
...attached file into config/initializers/ to be able to say in_columns on any Array: >> [1, 2, 3, 4, 5, 6, 7].in_columns(3)
...1, 2, 3, 4, 5, 6, 7].in_columns(2) => [[1, 3, 5, 7], [2, 4, 6]] While in_groups and in_groups_of are provided by Rails this also...
...browser based test runner. Should be easily adaptable to a pure Webpack setup. Step 1: Install Jasmine yarn add jasmine-core Step 2: Add two separate packs
...look at their titles like this: messages[0].find('h2').text => "Hello World" messages[1].find('h2').text => "Hello Universe" So far, so good. Now we want to find titles...
...using a "full" selector to avoid the broken behavior: page.find('.message:nth-of-type(1)', :text => 'Hello World').text => "Hello World" page.find('.message:nth-of-type(2)', :text => 'Hello World...
def hello 'world' end ^ $ git blame foo d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 1) def hello d47bf443 (Arne Hartherz 2012-12-19 14...
d47bf443 (Arne Hartherz 2012-12-19 14:44:38 +0100 3) end Now it's being changed to: def hello if world? 'world' else 'universe' end end
...change their title from the prompt, run this function: function tab_title { if [ -z "$1" ] then title=${PWD##*/} # current directory else title=$1 # first param fi