Skip to content

Instantly share code, notes, and snippets.

View chris-marsh's full-sized avatar

Chris Marsh chris-marsh

View GitHub Profile
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'scrooloose/nerdtree.git'
Plugin 'kien/ctrlp.vim'
Plugin 'flazz/vim-colorschemes'
@chris-marsh
chris-marsh / split_opts.sh
Last active February 3, 2016 21:48
Shell script to take an argument list and expand any grouped short options. For example; -lotr becomes -l -o -t -r.Compatible with most shells. Tested on Bash, Dash and BusyBox.
#!/bin/bash
#
# Chris Marsh 2016
# Written for compatibility. Tested on Bash and BusyBox.
#
# -----------------------------------------------------------------------------
# Takes an argument list and expand any group short arguments into seperate
# options.
# Usage: eval "set -- $(split_opts "$@")"
# eval "set -- $(split_opts "-lotr -file /some/file.txt)"
@chris-marsh
chris-marsh / grok_vi.mdown
Created February 16, 2016 15:32 — forked from nifl/grok_vi.mdown
Your problem with Vim is that you don't grok vi.

Answer by Jim Dennis on Stack Overflow question http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim/1220118#1220118

Your problem with Vim is that you don't grok vi.

You mention cutting with yy and complain that you almost never want to cut whole lines. In fact programmers, editing source code, very often want to work on whole lines, ranges of lines and blocks of code. However, yy is only one of many way to yank text into the anonymous copy buffer (or "register" as it's called in vi).

The "Zen" of vi is that you're speaking a language. The initial y is a verb. The statement yy is a simple statement which is, essentially, an abbreviation for 0 y$:

0 go to the beginning of this line. y yank from here (up to where?)

@chris-marsh
chris-marsh / gui.c
Created January 5, 2017 21:14
Design pattern: First Class Abstract Data Type
#include <gtk/gtk.h>
#include <string.h>
#include <stdlib.h>
typedef struct Window* WindowPtr;
struct Window {
char *title;
GtkWidget *win;
};
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
typedef struct {
char *key;
char *value;
@chris-marsh
chris-marsh / .vimrc
Last active December 18, 2023 19:37
My vimrc Without plugins
set nocompatible
filetype off
set shell=/bin/bash
set hidden " opening new file hides current instead of closing
set nowrap " switch off line wrapping
set tabstop=4 " Set tabs to 4 characaters wide
set shiftwidth=4 " Set indentation width to match tab
set expandtab " Use spaces instead of actual hard tabs
set softtabstop=4 " Set the soft tab to match the hard tab width
@chris-marsh
chris-marsh / singleton.c
Created January 23, 2017 22:46
POSIX solution of a dual-role daemon, i.e. a single application that can act as daemon and as a client communicating with that daemon.
#include <stdio.h>
#include <stddef.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <signal.h>
#include <sys/socket.h>
#include <sys/un.h>
@chris-marsh
chris-marsh / send_sig.c
Last active January 25, 2017 16:43
ANSI std C89/99 to send kill signals using system
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>
#include <unistd.h>
#include <sys/wait.h>
void send_sig(int pid, int sig)
{
char exec_str[128];
@chris-marsh
chris-marsh / instance.c
Created January 26, 2017 22:55
Only open a unique instance of an application.
include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <sys/file.h>
#include <sys/wait.h>
#define TRUE 1
#define FALSE 0