Skip to content

Instantly share code, notes, and snippets.

View czj's full-sized avatar

Clément Joubert czj

View GitHub Profile
@czj
czj / prompt.txt
Created May 9, 2023 16:18
ChatGPT / LLM language detection prompt that does not work well at all
Different languages use different writing systems, such as the Latin alphabet, Cyrillic script, or Arabic script.
Examining the characters used in the text can provide clues about the language.
Identifying common words and phrases in the text can help narrow down the language.
Analyzing the patterns of grammar used in the text can help identify the language.
Languages have distinct grammar rules, including sentence structure, verb conjugation, and noun declension.
The way words are arranged in a sentence can also provide clues about the language.
By examining these and other linguistic features of a text, it is possible to make an educated guess about the language in which it is written.
Deducing the language of a text involves analyzing various linguistic features of the text and comparing them to patterns and characteristics of different languages. Seeing the name of a language inside the text does not automatically mean it is the language of the text.
@czj
czj / feed.xml
Created March 7, 2022 13:34
Le flux RSS de HomeCinéSolutions a déménagé
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="https://www.w3.org/2005/Atom">
<channel>
<atom:link href="https://www.homecinesolutions.fr/p.rss" rel="self" type="application/rss+xml"/>
<title>Notre flux RSS a déménagé !</title>
<description>Notre flux RSS a déménagé !</description>
<link>https://www.homecinesolutions.fr/p.rss</link>
<item>
<title>Notre flux RSS a déménagé !</title>
<pubDate>Sat, 05 Mar 2022 15:41:16 +0100</pubDate>
@czj
czj / form_builder_errors.rb
Created September 13, 2021 11:49
Rails 6+ helpers to display a list of form errors, adapted for Bootstrap 5 syntax
# frozen_string_literal: true
# Nifty Generators - https://github.com/ryanb/nifty-generators
#
# copy from Nifty Generators,
# markup optimized for bootstrap
#
# Usage:
# <%= f.error_messages %>
# <%= error_messages_for(@object) %>
@czj
czj / RelatedFiles.sublime-settings.js
Created January 16, 2021 10:48
Related Files Plugin rules for view_component gem files in a Rails app
// https://github.com/fabiokr/sublime-related-files
{
"patterns": {
// Components Ruby classes
".+\/app\/components\/(.+).rb":
[
"app/components/$1.html.slim",
"app/components/$1.rb",
"app/components/$1.scss",
@czj
czj / example.rb
Created June 23, 2020 11:14
Ruby ceil() round() floor() with negative arguments
10.32.round(-1)
# 10
11.32.round(-1)
# 10
19.32.round(-1)
# 20
19.32.ceil(-1)
@czj
czj / TLDR.md
Created June 23, 2020 10:30
Comparing Ruby includes?() versus member?() performance

member? is a method of Enumerable, which is WAY slower for Array but not for Set

@czj
czj / array_vs_set_performance_test.rb
Created June 23, 2020 10:16
Ruby Array versus Set performance test
# frozen_string_literal: true
require "benchmark"
array = [4, 5, 6, 11, 12, 20, 40, 64, 65, 66, 81, 83].freeze
set = Set.new(array).freeze
n = 10_000_000
Benchmark.bm(7) do |x|
x.report("array found at position 0") { n.times { array.include?(4) } }
@czj
czj / rails_content_tag_vers_tag_benchmark.rb
Created June 11, 2020 13:01
Benchmarking Rails' `content_tag(:b)` vs `tag.b`
before = Process.clock_gettime(Process::CLOCK_MONOTONIC)
50_000.times { tag.span("hey") }
after = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Rails.logger.debug %(tag.span("hey") } #{after - before}s)
before = Process.clock_gettime(Process::CLOCK_MONOTONIC)
50_000.times { tag.span { "hey" } }
after = Process.clock_gettime(Process::CLOCK_MONOTONIC)
Rails.logger.debug %(tag.span { "hey" } } #{after - before}s)
@czj
czj / ruby-benchmark-env.key-or-env.bracket.rb
Created July 1, 2019 16:04
Why is faster : ENV["key"] or ENV.key?("key") ? The answer will surprise you ...
require "benchmark/ips"
HASH = ("a".."zz").to_a.shuffle.to_h { |e| [e, "#{e}#{e}#{e}"] }
KEY = "zz"
def key_fast
HASH.key? KEY
end
def key_slow
# Rewrite all commits without a certain directory
java -jar ~/Downloads/bfg-1.13.0.jar --delete-folders "vcr_cassettes"
# Remove garbage
git reflog expire --expire=now --all && git gc --prune=now --aggressive
# Push to your repo
git remote add origin [email protected]:my-org/my-repo.git
git push -u origin master