Skip to content

Instantly share code, notes, and snippets.

View kmatt's full-sized avatar
😐

Matt Keranen kmatt

😐
  • SE US
View GitHub Profile
@kmatt
kmatt / .tmux.conf
Last active August 29, 2015 14:18 — forked from mjswensen/.tmux.conf
set-window-option -g status-left " #S "
set-window-option -g status-left-fg black
set-window-option -g status-left-bg white
set-window-option -g status-right " %H:%M %d-%b-%y "
set-window-option -g status-right-fg black
set-window-option -g status-right-bg white
set-window-option -g window-status-format " #I: #W "
@kmatt
kmatt / columnice.py
Last active August 29, 2015 14:25 — forked from bas080/columnice.py
Easily columize code. Example would be "columnice.py ,". This will columize the text using the comma ',' as the delimeter.
#!/usr/bin/env python
import sys
def matrix( text, seperator_x='\t', seperator_y='\n'):
table = []
rows = text.split( seperator_y )
for index, row in enumerate( rows ):
table.insert( index, row.split( seperator_x ) )
return table
@kmatt
kmatt / send_mail.py
Last active August 29, 2015 14:27 — forked from vjo/send_mail.py
[Python] Send email with embedded image and application attachment
#! /usr/bin/python
import smtplib
from optparse import OptionParser
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication
@kmatt
kmatt / SQL.xml
Created February 21, 2011 20:39
SQL highlighting for PyCharm (and probably RubyMine, IntelliJ IDEA), with T-SQL specifics
<?xml version="1.0" encoding="UTF-8"?>
<filetype binary="false" default_extension="" description="SQL" name="SQL">
<highlighting>
<options>
<option name="LINE_COMMENT" value="--" />
<option name="COMMENT_START" value="/*" />
<option name="COMMENT_END" value="*/" />
<option name="HEX_PREFIX" value="" />
<option name="NUM_POSTFIXES" value="" />
<option name="HAS_BRACKETS" value="true" />
@kmatt
kmatt / sqlpostgres.vim
Created May 21, 2012 16:09 — forked from chanmix51/sqlpostgres.vim
SQL postgres vim syntax file
" Vim syntax file
" Language: SQL, PGSQL (postgres 9.1)
" Last Change: 2012 May 21st
" Maintainer: Grégoire Hubert <greg DOT hubert AT gmail DOT com>
" Based on the work of Paul Moore <pf_moore AT yahoo.co.uk>
" For version 5.x: Clear all syntax items
" For version 6.x: Quit when a syntax file was already loaded
if version < 600
syntax clear
@kmatt
kmatt / gist:2848105
Created June 1, 2012 02:17 — forked from mikeyk/gist:1329319
Testing storage of millions of keys in Redis
#! /usr/bin/env python
import redis
import random
import sys
r = redis.Redis(host = 'localhost', port = 6389)
REDIS_SETGET = False
REDIS_HSET = False
@kmatt
kmatt / gist:2848112
Created June 1, 2012 02:18
The Zen of R
# I am a scientist who has been using R for about 2 years. Today I achieved a measure of enlightenment into
# the zen of R, and I want to share it with you.
# I was simulating a set of independent random walks, which are formed by a multiplicative process. Here is
# the code I had built up over a few months of working on it and modifying it on and off as research
# questions changed:
TimeSteps <- 1000
Walks <- 100
ErrorMagnitude <- 0.03
@kmatt
kmatt / mySplitDump.sh
Created June 8, 2012 19:45
Split MySQL dumps
file=$1
nextDB=""
nextStart=0
nextEnd=0
lastDB=""
lastStart=0
for i in `grep -n "^CREATE DATABASE" $file | awk '{print $1":"$7}' | sed "s/CREATE://g"`
do
@kmatt
kmatt / RestoreLastBak.ps1
Created June 21, 2012 17:07
Restore SQL Server backups from wildcard path
param ($bakpath, $dbname, $instance, $datapath, $logpath, [switch]$norecovery, [switch]$replace, [switch]$rollback, [switch]$standby, [switch]$test)
# Restore latest backup from wildcard path, optionally forcing out open connections
# Used to restore backups copied to a standby or test server
""
# SQL 2008 PS module imports
#[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.SqlServer.SMO') | out-null
#if ((get-pssnapin sqlserverprovidersnapin100 -ErrorAction "SilentlyContinue") -eq $NULL) { add-pssnapin sqlserverprovidersnapin110 }
#if ((get-pssnapin sqlservercmdletsnapin100 -ErrorAction "SilentlyContinue") -eq $NULL) { add-pssnapin sqlservercmdletsnapin110 }
@kmatt
kmatt / gist:3351502
Created August 14, 2012 18:28 — forked from karlseguin/gist:2992426
sample code used by ranking post
# http://openmymind.net/Paging-And-Ranking-With-Large-Offsets-MongoDB-vs-Redis-vs-Postgresql/
lids = ['4fe907f1210b2e9e3080f001', '4fe907f1210b2e9e3080f002', '4fe907f1210b2e9e3080f003', '4fe907f1210b2e9e3080f004', '4fe907f1210b2e9e3080f005']
insert the data
open('data.csv', 'w') do |f|
6000000.times do |i|
f.puts "#{lids.sample},user_#{i},#{(rand() * 10000000).to_i}"
end
end