Skip to content

Instantly share code, notes, and snippets.

Andrew Radev AndrewRadev

View GitHub Profile
@AndrewRadev
AndrewRadev / vim_guide.md
Created Apr 24, 2020
An old Vim guide I wrote in Bulgarian. Originally published at https://github.com/fmi/ruby-course-guides/blob/master/vim.md#readme
View vim_guide.md

Vim

TL;DR – VIM EMERGENCY!

  • За да излезете от Vim, без да запазвате файл, натиснете Esc, след това напишете :q! и натиснете Enter.
  • За да направите промяна, натиснете i и си редактирайте текста като в нормален редактор.
  • За да запазите направените промени, натиснете Esc и след това напишете :w и натиснете Enter. След това е окей да излезете от редактора с :q.

А ако се чудите къде да инвестирате следващите десет минути от живота си, непременно прочетете това ръководство до края.

@AndrewRadev
AndrewRadev / efactory.vim
Last active Apr 14, 2020
An `:Efactory` command for jumping to factory_bot definitions in rails projects
View efactory.vim
" Extracted from:
" https://github.com/AndrewRadev/Vimfiles/blob/0490041cf2d0e4f7a9b2e1361bb47971dd59d836/miniplugins/plugin/rails_extra.vim
"
" Installation:
"
" Copy file to ~/.vim/plugin/efactory.vim, or just paste the whole thing in
" your `.vimrc`. No guarantees it'll work well for you, seems to work for me.
" Will extract to a plugin at some point and it'll hopefully be more reliable.
"
" Usage:
@AndrewRadev
AndrewRadev / main.rs
Last active Nov 13, 2018
Divide successfully or default to zero
View main.rs
trait OrZero {
fn or_zero(self) -> Self;
}
impl OrZero for f64 {
fn or_zero(self) -> Self {
if self.is_normal() { self } else { 0.0 }
}
}
@AndrewRadev
AndrewRadev / keep-track.sh
Last active Oct 21, 2018
Keep track of a long-running process
View keep-track.sh
# Given a long-running process in the terminal:
#
# - Ctrl+Z to suspend it
# - Run `keep-track`
# - Output resumes, when done will show a notification with the time it took for the process to run
#
# Can be customized with an `--icon` to `notify-send`,
# maybe a sound effect added in the `&&` list.
#
function keep-track() {
View hangman_main.rs
extern crate solution;
use solution::*;
use std::io::{self, Write};
fn main() {
let mut game = Game::new("aardvark", 10).unwrap();
let stdin = io::stdin();
println!("Let's play hangman!");
@AndrewRadev
AndrewRadev / jsx.vim
Last active May 30, 2017
gf for react
View jsx.vim
set includeexpr=<SID>Includeexpr()
augroup jsx_autocommands
autocmd!
" Override gf if rails sets it after
autocmd User Rails cmap <buffer><expr> <Plug><cfile> <SID>Includeexpr()
augroup END
function! s:Includeexpr()
@AndrewRadev
AndrewRadev / ascii_image.rs
Last active Mar 21, 2017
Convert an image to simple ASCII-art
View ascii_image.rs
extern crate image;
use std::io::File;
use image::GenericImage;
fn main() {
let path = Path::new("examples/test_image.png");
let file = File::open(&path);
match image::load(file, image::ImageFormat::PNG) {
View ftplugin_ruby.vim
" Define what color the private area will be
hi rubyPrivateArea ctermbg=darkgray
function! s:MarkPrivateArea()
" Clear out any previous matches
call clearmatches()
" Store the current view, in order to restore it later
let saved_view = winsaveview()
@AndrewRadev
AndrewRadev / lebab.vim
Last active Apr 17, 2018
Use the "lebab" tool through Vim
View lebab.vim
" Invoke the `lebab` tool on the current buffer (https://github.com/lebab/lebab)
"
" Usage:
"
" :Lebab <transform1> <transform2> [...]
"
" This will run all the transforms specified and replace the buffer with the
" results. The available transforms tab-complete.
"
command! -nargs=+ -complete=custom,s:LebabComplete
View indent_test_large_complex_file.rb
class AroundEverything
class Nested
def example
some_chain.continued_on.
next_line.method do |one, two|
<<-EOF
Body of method
EOF
end
You can’t perform that action at this time.