In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.
Some examples:
7 # integer literal| #!/bin/bash | |
| # Check if fzf is installed | |
| if ! command -v fzf &> /dev/null; then | |
| echo "Error: fzf is not installed. Please install it first." | |
| echo "You can install it with:" | |
| echo " - On macOS: brew install fzf" | |
| echo " - On Ubuntu/Debian: sudo apt install fzf" | |
| echo " - On other systems: see https://github.com/junegunn/fzf#installation" | |
| exit 1 |
In programming languages, literals are textual representations of values in the source code. This is a syntactical concept.
Some examples:
7 # integer literal| require 'fileutils' | |
| # Loop through all .jpg and .png files in the current directory | |
| Dir.glob("{*.jpg,*.png}").each do |img| | |
| # Construct the output filename with .webp extension | |
| output_filename = "#{File.basename(img, File.extname(img))}.webp" | |
| # Execute ffmpeg command to convert the image | |
| system("ffmpeg -i '#{img}' '#{output_filename}'") | |
| end |
| #! /usr/bin/env zsh | |
| file=$(fd -e rb -H -1 | shuf -n 1) | |
| line=$(shuf -i 1-$(($(wc -l < "$file") + 1)) -n 1) | |
| awk -v line="$line" 'NR==line{$0="# GOOD_JOB: YOU PROBABLY FORGOT TO REMOVE THIS COMMENT DIDNT YOU\n"$0}1' "$file" > temp && mv temp "$file" |
| . _///_, | |
| . / ` ' '> | |
| ) o' __/_'> | |
| ( / _/ )_\'> | |
| ' "__/ /_/\_> | |
| ____/_/_/_/ | |
| /,---, _/ / | |
| "" /_/_/_/ | |
| /_(_(_(_ \ | |
| ( \_\_\\_ )\ |
| def active_link_to(name = nil, options = nil, **html_options, &block) | |
| options = block_given? ? name : options | |
| if current_page?(options) | |
| html_options[:class] = class_names(html_options[:class], :active) | |
| html_options[:aria] = html_options.fetch(:aria, {}).merge(current: :page) | |
| end | |
| if block_given? | |
| link_to options, html_options, &block |
| # This should be triggered through a cron job at 6:15 PM on week days. | |
| # Example cron: 15 18 * * 1,2,3,4,5 cd ~/code/jury_duty && ~/.rbenv/shims/ruby call.rb >> ~/code/jury_duty/call-log.txt 2>&1 | |
| # It uses Twilio to make a call based on TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, and TWILIO_PHONE. | |
| # It calls the JURY_PHONE, transcribes it, looks for JURER_NUMBER and texts the result to PERSONAL_PHONE. | |
| require "rubygems" | |
| require "bundler/setup" | |
| Bundler.require(:default) | |
| Dotenv.load |
| #!/usr/bin/env ruby | |
| # frozen_string_literal: true | |
| require "bundler/inline" | |
| gemfile do | |
| source "https://rubygems.org" | |
| gem "syntax_tree" | |
| end |
| # In Active Record, class method scopes have to remember to return `all` otherwise they're break the call chain. | |
| # | |
| # def self.some_scope = nil # Assume more complex conditions that would result in a branch that accidentally didn't return `all`. | |
| # | |
| # User.some_scope.first # => raises NoMethodError `first' for NilClass | |
| # | |
| # Note: Active Record ensures a `scope :some_scope, -> { nil }` returns `all` via `|| all` here: | |
| # https://github.com/rails/rails/blob/c704da66de59262f4e88824589ae4eddefb6ed4a/activerecord/lib/active_record/scoping/named.rb#L181 | |
| # | |
| # Now, this extension allows you to mark a class method as a scope, so you don't have to remember and the code is more clearly demarcated too. |
| #!/bin/bash | |
| # Usage: gifify.sh <input file> <output file> | |
| ffmpeg -i $1 -vf "fps=10,scale=320:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" $2 |