Skip to content

Instantly share code, notes, and snippets.

@praetoriansentry
Last active September 29, 2015 06:07
Show Gist options
  • Save praetoriansentry/1557012 to your computer and use it in GitHub Desktop.
Save praetoriansentry/1557012 to your computer and use it in GitHub Desktop.
Snippets
set nocompatible
set number
set ruler
syntax on
" Set encoding
set encoding=utf-8
" Whitespace stuff
set nowrap
set tabstop=4
set shiftwidth=4
set softtabstop=4
set expandtab
set list listchars=trail:·,tab:>.
set directory^=C:\tmp
set backupdir^=C:\tmp
" Searching
set hlsearch
set incsearch
set ignorecase
set smartcase
" Tab completion
set wildmode=list:longest,list:full
set wildignore+=*.o,*.obj,.git,*.rbc,*.class,.svn,vendor/gems/*
" Status bar
set laststatus=2
" Without setting this, ZoomWin restores windows in a way that causes
" equalalways behavior to be triggered the next time CommandT is used.
" This is likely a bludgeon to solve some other issue, but it works
set noequalalways
" Remember last location in file
if has("autocmd")
au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
\| exe "normal g'\"" | endif
endif
function s:setupWrapping()
set wrap
set wrapmargin=2
set textwidth=72
endfunction
function s:setupMarkup()
call s:setupWrapping()
map <buffer> <Leader>p :Hammer<CR>
endfunction
" add json syntax highlighting
au BufNewFile,BufRead *.json set ft=javascript
" markdown filetype file
au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=mkd
au BufRead,BufNewFile *.txt call s:setupWrapping()
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" load the plugin and indent settings for the detected filetype
filetype plugin indent on
" Default color scheme
"color slate
color solarized
" Show (partial) command in the status line
set showcmd
" my stuff
"
" CTRL-X and SHIFT-Del are Cut
vnoremap <C-X> "+x
vnoremap <S-Del> "+x
" CTRL-C and CTRL-Insert are Copy
vnoremap <C-C> "+y
vnoremap <C-Insert> "+y
" CTRL-V and SHIFT-Insert are Paste
map <C-V> "+gP
map <S-Insert> "+gP
cmap <C-V> <C-R>+
cmap <S-Insert> <C-R>+
exe 'inoremap <script> <C-V>' paste#paste_cmd['i']
exe 'vnoremap <script> <C-V>' paste#paste_cmd['v']
imap <S-Insert> <C-V>
vmap <S-Insert> <C-V>
" Use CTRL-Q to do what CTRL-V used to do
noremap <C-Q> <C-V>
map <C-A> ggVG
:set guioptions-=m "remove menu bar
:set guioptions-=T "remove toolbar
:set guioptions-=r "remove right-hand scroll bar
REM this is a simple way to use pandoc to convert markdown to html
REM the -s is for standalone mode
pandoc -s -f markdown -t html -c styles.css markdown.md > output.html
REM This is a good way to run tidy for xml
tidy -xml -i -w 0 test.xml > clean.xml
REM os independent way of going from markdown to man page
pandoc -s -f markdown -t man chapter2.md | groff -Tascii -m man -Z | grotty -cbuo
<?php
// This is a simple php pattern for a singleton
class TestClass {
private static $_instance = 0;
private $foo;
public static function Instance() {
if (self::$_instance === 0) {
self::$_instance = new TestClass();
}
return self::$_instance;
}
protected function __construct() {
$this->foo = 'bar';
}
public function getFoo() {
return $this->foo;
}
}
$test = TestClass::Instance();
print $test->getFoo();
#!/opt/local/bin/perl
#This is a simple snippet that reads all of the files that are passed in line by line
use utf8;
while (<>) {
chomp;
}
# How to connect to a database in R
require(RODBC)
con<-odbcConnect('rpt')
rawdata <- sqlQuery(con,"
SELECT
*
from
table
")
odbcClose(con)
remove(con)
#replace NA elements in a column in a dataframe
df$col[is.na(df$col)]<-0
#save data to file
png("filename", width=1600, height=1200)
qplot(...)
dev.off()
# Append a line to a file as sudo
echo "Line to append" | sudo tee --append /file/to/append
# Remove Carriage return characters from a file ^M
<filename tr -d '\r' > filename
# Do a full packet capture
sudo tcpdump -w dianose.pcap -i any -s 0
--Test if a temp table exists. if not, drop it
IF object_id('tempdb..#temptb') is not null
BEGIN
DROP TABLE #temptb
END
-- function to get one version of the iso 8601 format for a week
DECLARE @now DATETIME
SET @now = GETDATE()
SELECT
CAST (DATEPART (YEAR, @now) AS VARCHAR (4)) + '-W' + RIGHT ('0' + CAST (DATEPART (week, @now) AS VARCHAR (2)), 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment