Most forms have a single submit button that will save the record when pressed. Sometimes a form needs additional submit buttons like "accept" or "reject". Such buttons usually attempt...
...a state transition while updating the record. To process a form with multiple buttons, your server-side code will need to know which button was pressed. To do so you...
View specs are a powerful tool to test several rendering paths by their cases instead of using a more costing feature spec. This is especially useful because they become quite...
...used with Capybara::Node::Finders and Capybara::RSpecMatchers. This allows to wirte view unit specs as you can isolate specific parts of the rendered view and then use readable and...
...However, you need to be aware of the overall transaction nesting constellation, because creating proper sub-transactions can lead to unwanted or too early triggering of after_commit callbacks:
...project> Country.first.name # => "Afghanistan will not change" Wait. What happened to the rollback in the after_save-callback? From the Rails docs: Transaction calls can be nested. By default, this makes...
Matching the "space" character class For matching whitespaces in a regular expression, the most common and best-known shorthand expression is probably \s. It matches the following whitespace characters:
...in some cases these may not be good enough for your purpose. Non-breaking spaces (nbsp) Sometimes a text may contain two words separated by a space, but the author...
Any form fields where users enter numbers should be an . Numeric inputs have several benefits over : On mobile or tablet devices, number fields show a special virtual keyboard that shows...
...mostly digit buttons. Decimal values will be formatted using the user's language settings. For example, German users will see 1,23 for . Values in the JavaScript API or when...
Slides for Henning's talk on Sep 21st 2017. Understanding sync vs. async control flow Talking to synchronous (or "blocking") API print('script start') html = get('/foo') print(html)
Script outputs 'script start', (long delay), '...
...', 'script end'. Talking to asynchronous (or "evented") API print('script start') get('foo', done: function(html) { print(html) }) print('script end')
Note: Consider using MATE instead of Gnome 3 on newer system Awesome is a very good tiling window manager that provides neat features like automatic layouting of windows, good multi...
Improve your font-rendering Copy /etc/xdg/awesome/rc.lua to ~/.config/awesome/rc.lua. Take a look, it's pretty self-explanatory. You can instantly apply changes by reloading Awesome with Meta-Ctrl-R.
When you need test images, instead of using services like lorempixel or placehold.it you may generate test images yourself. Here we build a simple SVG image and wrap it into...
...a data: URI. All browsers support SVG, and you can easily adjust it yourself. Simply set it as an image's src attribute. JavaScript Simple solution in modern JavaScript, e.g...
...update your window title whenever you switch directories, simply specify a PROMPT_COMMAND environment variable. set-window-title() { echo -en "\033]0;$(pwd | sed -e "s;^$HOME;~;")\a" } if [[ "$PROMPT...
...COMMAND" ]]; then export PROMPT_COMMAND="$PROMPT_COMMAND;set-window-title" else export PROMPT_COMMAND=set-window-title fi You may put that into your ~/.bashrc to persist and automatically activate...
...is hard coded. A popular example is extension_allowlist, which returns an array of strings and let's you only upload files that have a filename with an extension that...
...matches an entry in that array. Another useful validation can be size_range, which gives you a little bit of control over how your storage gets polluted.
This card compares patterns to store trees in a relation database like MySQL or PostgreSQL. Implementation examples are for the ActiveRecord ORM used with Ruby on Rails, but the techniques...
We will be using this example tree (from the acts_as_nested_set docs): root | +-- Child 1 | | | +-- Child 1.1 | | | +-- Child 1.2 | +-- Child 2 | +-- Child 2.1 | +-- Child 2.2
RAG is often equated with vector databases, embeddings, and semantic search. But RAG ("Retrieval-Augmented Generation") really is just 'put relevant data in the prompt' — the retrieval mechanism is up...
...to you. If your app already has any working search functionality, you can build a useful RAG pipeline with it. Semantic search can still be included later on, if really...
...chat messages, and it will load them into its context for analysis. Note For scanned pages that may be sideways or upside down, auto-rotate them first. Autocrop assumes upright...
...px so text remains readable. To convert PDF pages to scaled down images: pdftoppm -png -scale-to 1500 input.pdf output_prefix Convert images to thumbnails: vipsthumbnail input.png --size 1500x1500 -o...
...handy when values have an implicit ordering. Let's imagine a record Issue(criticality: string). criticality should have the following three possible values: critical, medium, low. Sorting with Issue.all.order(criticality...
...critical' issue This happens because the database column backing the criticality attribute is a string and PG will use a collation to determine the result of comparisons. In most collations...
...behavior, you can explicitely tell ActiveRecord how to preload associations with either JOINs or separate queries. This card gives an overview of the different options to preload associations, but
...for preloading! Please have a look on on our card why you should be super careful with complex eager_load or includes queries. Thus, as a general guideline.includes or .eager...
When debugging slow SQL queries, it’s helpful to understand the database engine's query plan. Whenever you execute a declarative SQL query, the database generates a "query plan" that...
...outlines the exact steps the engine will take to execute the query. Most of the time, we don’t need to worry about this plan because SQL engines are highly...
...the everyday use without any parameter tweaking I'm using a collection of tiny scripts in my ~/bin folder that can then be used as bash functions. And: It's...
...video-to-audio /path/to/cake.mp4 cake.mp3 audio-to-audio /path/to/cake.mp3 cake.aac image-to-image /path/to/cake.png cake.jpg stateDiagram-v2 text --> image: Dall-E 3 text --> audio: GPT TTS image --> text: GPT Vision...
...or not to gem": Gem is really needed (prefer writing your own code for simple requirements without many edge cases) Gem is tested well (coverage and quality)
...the project requirement Try to avoid gems that do much more than your requirement scope needs Gem has a good maturity and maintenance Gem has a good / familiar DSL
...browser trust the certificate so it does not show warnings for your own certificate. Easy: self-signed certificate To just create a certificate for localhost, you can use the following...
...can then access your application at https://localhost:3000/. Your browser will complain about the self-signed certificate, but you can ignore the warning in that case, since you are...
...in coding lies in crafting precise prompts. The main challenge is learning how to structure prompts effectively to guide the model toward accurate results. Further evidence supporting this is the...
...that Aider already writes ~70% of its own code (as of 02/2025). However, when starting out, your results may fall short of efficiently generating large portions of your code with...
Postgres supports multiple built-in range datatypes: int4range int8range numrange tsrange (range with timestamp without timezone) tstzrange (range with timestamp with timezone) daterange They represent a start and endpoint of...
...something in a single column. Image you're building a vacation booking feature: create_table :events do |t| t.date :starts_on t.date :ends_on end This is how you would...
...It must be fixed by patching the Jasmine sources. Fix for Webpacker Add the package string-replace-loader to your package.json. If you're on Webpacker 5 (Webpack 4) the...
...your config/webpack/environment.js: environment.loaders.prepend('fix-jasmine4-global-detection', { test: /jasmine-core\/lib\/jasmine-core\/jasmine\.js$/, use: [{ loader: 'string-replace-loader', options: { search: 'window.toString() === \'[object GjsGlobal]\'', replace: 'window.toString() === \'[object Window]\'' } }] }) Fix for ESBuild...
...some behavior you may eventually run into when upgrading your application. This aims to save you some time understanding what happens under the hood to possibly discover problems faster as...
...renamed to denylists. You will have to rename all occurrences in your code. Make sure that you have defined a trait for validating the extensions and content types in all...
This card is a general reminder to avoid the short version of a command option in shared code. It's much easier to understand a command and search for an...
...option when it's written out. You can still use the short version of the options in your own terminal or in code snippets that are more useful when they...