Skip to content

Instantly share code, notes, and snippets.

View jchros's full-sized avatar

Jason Chrosrova jchros

  • Toulouse, France
View GitHub Profile
inoreabbrev <buffer> <expr> += '= ' .. getline('.')->matchstr('\c\(assign\s*\)\?\zs\S.*\ze+=') .. '+'
inoreabbrev <buffer> <expr> *= '= ' .. getline('.')->matchstr('\c\(assign\s*\)\?\zs\S.*\ze\*=') .. '*'
inoreabbrev <buffer> <expr> -= '= ' .. getline('.')->matchstr('\c\(assign\s*\)\?\zs\S.*\ze-=') .. '-'
inoreabbrev <buffer> <expr> /= '= ' .. getline('.')->matchstr('\c\(assign\s*\)\?\zs\S.*\ze/=') .. '/'
@jchros
jchros / tags
Created October 19, 2022 01:41
Tagfile containing every (non-deprecated) Neovim command as of version 0.8.
:a insert.txt /*:a*
:ab map.txt /*:ab*
:abbreviate map.txt /*:abbreviate*
:abc map.txt /*:abc*
:abclear map.txt /*:abclear*
:abo windows.txt /*:abo*
:aboveleft windows.txt /*:aboveleft*
:addd quickfix.txt /*:addd*
:al windows.txt /*:al*
:all windows.txt /*:all*
@jchros
jchros / elo.lisp
Last active April 23, 2022 08:04
A Common Lisp library for the Elo ranking system.
(defpackage :elo
(:use :cl))
(in-package :elo)
(defvar *expected-outcome-fun* nil
"This is used to supply an alternative function for
calculating the expected outcome of a game (whose
arguments are the Elo scores of the two players, and
returns a number between 0 and 1).
" Parses Vimscript commands
" Caveats:
" - Assumes that "a:source" is a well-formed single-line Vim command; it doesn't always fail gracefully otherwise
" - Assumes there is only one command (i.e. "|"s are part of the arguments of the command and aren't used as separators)
" - For ":!" commands, "cmd" is an empty string, "has_bang" is TRUE, and "args" is the entire shell command
func ParseCmd(source) abort
" sorry.
let res = matchlist(a:source, '^[ \t:]*\%(\(\%([%.$,;]\|[''\\].\|[-+]\?\d\+\%(\s*match\)\@!\|\([/?]\).\{-\}[^//]\%(\\\\\)*\%(\2\|$\)\)*\)\s*\(\%(\a\|\d\)*\)\(!\?\)\s*\(.*\)\&[^"#]\)')
return empty(res) ? {} : #{
\ source: res[0],
(defmacro valsetf (values-form . places)
"Assigns the values of VALUES-FORM to the given PLACES.
If VALUES-FORM yields more values than there are fields in PLACES, the
remaining values are discarded. If there are more fields in PLACES
than there are values returned by the VALUES-FORM, the remaining
fields are initialized to NIL."
(assert places)
(let* ((*gensym-counter* 1)
(gensyms (mapcar #'(lambda (_)
fu! Bezout(lhs, rhs) abort
let r = [a:lhs, a:rhs]
let [u, v] = [[1, 0], [0, 1]]
while r[1] != 0
let q = r[0] / r[1]
let r = [r[1], r[0] % r[1]]
let u = [u[1], u[0] - u[1] * q]
let v = [v[1], v[0] - v[1] * q]
endwhile
return #{
@jchros
jchros / blackjack.swift
Created July 14, 2020 18:49
The first Swift (4) program I've ever written (August 2018).
import Foundation
//MARK: Enumerations and Classes
enum Suit {
case hearts, diamonds, clubs, spades
}
enum Language {
@jchros
jchros / Example.swift
Last active October 28, 2020 20:44
A library for solving the 0-1 knapsack problem (inspired by https://rosettacode.org/wiki/Knapsack_problem/0-1#Swift )
/// An example implementation of the `KnapsackItem` protocol.
struct Example: KnapsackItem, CustomStringConvertible {
var name: String
var weight: Int
var value: Int
var description: String { name }
}
@jchros
jchros / .vimrc
Last active February 14, 2020 10:44
" tinyvimrc
se nu rnu hid ttm=100 list lcs=tab:\|\ ,trail:·
" Version-specific settings{{{
if has('cmdline_info')
se sc
endif
if has('extra_search')
se is hls
noh