Skip to content

Instantly share code, notes, and snippets.

View AndrewRadev's full-sized avatar

Andrew Radev AndrewRadev

View GitHub Profile
@AndrewRadev
AndrewRadev / keep-track.sh
Last active October 21, 2018 17:23
Keep track of a long-running process
# 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() {
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 07:15
gf for react
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 March 21, 2017 14:52
Convert an image to simple ASCII-art
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) {
" 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 April 17, 2018 18:58
Use the "lebab" tool through 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
class AroundEverything
class Nested
def example
some_chain.continued_on.
next_line.method do |one, two|
<<-EOF
Body of method
EOF
end
module ActiveRecord
class Attribute # :nodoc:
class << self
def from_database(name, value, type)
FromDatabase.new(name, value, type)
end
def from_user(name, value, type)
FromUser.new(name, value, type)
end
@AndrewRadev
AndrewRadev / benchmark.vim
Created January 5, 2017 15:58
A simple benchmark for vim-ruby indentation
function! s:Stats(list)
let sum = 0
for item in a:list
let sum += item
endfor
let mean = sum / len(a:list)
let sum_deviations = 0
for item in a:list
@AndrewRadev
AndrewRadev / convert_dict.vim
Created December 28, 2016 12:15
Convert a python dict into a tuple of pairs
command! ConvertDict call s:ConvertDict()
function! s:ConvertDict()
" Save view for restoring later
let saved_view = winsaveview()
" If we're not in a dict, do nothing
if searchpair('{', '', '}', 'bcW', '', line('.')) <= 0
return
endif