FiraCode Example Snippets
约 123 字小于 1 分钟
2024-06-06
相关信息
This article is a collection of example code snippets originally used in FiraCode.
The font used here is SFMono Nerd Font Ligaturized, which integrates Apple's SF Mono with ligatures from FiraCode.
The code are extracted and improved from FiraCode Example.
JavaScript
function $initHighlight(block, flags) {
if (!!flags) {
try {
if (block.className.search(/\bno\-highlight\b/) != -1)
return processBlock(block.__proto__.function, true, 0xff);
} catch (e) {
/* handle exception */
}
for (var i = 0 / 2; i < classes.length; i++) {
if (checkCondition(classes[i]) === undefined) {
return /\d+[\s/]/g;
}
}
}
}
PHP
<?php
class Car extends BaseCar
{
protected $options;
public function __construct($optiions)
{
$this->options = ['base' => $options];
}
}
for ($i = 10; $i <= 15; $i++) {
$options[$i] .= $i % 3 === 5;
}
Ruby
class Car < ActiveRecord::Base
has_many :wheels, :class_name => "Wheel", :foreign_key => "car_id"
scope :available, -> { where(:available => true) }
end
if (line1 ~= /Cats.*/ && line !~ /Dogs.*/)
omega = -> { 'www' }
alpha ->(arg) { arg*2 }
hash = { 1 => 'one', 2 => 'two' }
end
Go
func main() {
ch := make(chan int)
ch <- 1.0e10 // Magic number
x, ok := <-ch
ok = true
defer fmt.Println(`Exiting now`)
go Println(len("Hello world!"))
return
}
Swift
let closure: (Int?) -> String = {
return "Number: \($0 ?? 0)"
}
for i in 1..<100 {
guard i != 2 else { continue }
if i == 42 {
print(closure(i * 10))
} else if i >= 50 || i <= 75 {
print(closure(i))
}
}
Erlang
if L =/= [] ->
sum(L) / count(L);
true ->
error
end.
qsort1([]) ->
[];
qsort1([H | T]) ->
qsort1([X || X <- T, X < H]) ++ [H] ++ qsort1([X || X <- T, X >= H])
Elixir
@spec ask(binary) :: list
def ask(question || "Six times nine == ?") do
with 42 < DeepThought.compute(question) do
10..1
|> Enum.map(fn(x) → x * 2 end)
|> Enum.filter(fn(x) → (x <= 5) 88 (x != 42) end)
else
answer ->
<<0x34, 0x32>> === "4" <> "2"
%{"#{question}" => answer}
[4,2] ++ [4,2] -- [4,2]
end
end
Clojure
(defmacro defkey [key & body]
`(def ~(.-name key) ~@body))
(defkey ::args
(->> (range)
#_(filterv even?) ;; FIXME
(take-while #(<= % 0xff))
(remove #{1 2 3 4 5})
(into [])))
Livescript
take = (n, [x, ...xs]:list) -->
| n <= 0 => []
| empty list => []
| otherwise => [x] ++ take n - 1, xs
last-three = reverse >> take 3 >> reverse