Skip to content

Instantly share code, notes, and snippets.

@joequery
joequery / gist:6232325
Created August 14, 2013 15:45
Quick jarnal notes
jarnal $(date +"notes_%b_%d_%Y.jaj" | tr '[:upper:]' '[:lower:]')
@joequery
joequery / gist:6232026
Last active December 21, 2015 01:59 — forked from goatslacker/gist:6004481
Create a parseable time tracking log for vim. Requires https://gist.github.com/joequery/6231493 for the `git info` command.
" Lets me know how much time I've spent editing a file
" Keyboard shortcut -> \dt
augroup TimeSpentEditing
au!
au BufWinEnter * if !exists('b:tstart')|let b:tstart=reltime()|en
augroup END
function! TimeSpentEditing()
let secs = str2nr(reltimestr(reltime(b:tstart)))
let hours = secs / 3600
@joequery
joequery / gist:6231493
Created August 14, 2013 14:19
Git some information about a repo if possible.
#!/usr/bin/env python
import subprocess
import os
F_DEVNULL = open(os.devnull, 'w')
p = subprocess.Popen(["git", "rev-parse", "--show-toplevel"],
stdout=subprocess.PIPE, stderr=F_DEVNULL)
repo_root, err = p.communicate()
repo_root = repo_root.strip()
@joequery
joequery / gitfixup.py
Last active December 20, 2015 02:29
This script searches through the git log for the current directory you're in and starts an interactive rebase on a "base commit", which is simply a commit that doesn't start with "fixup! "
#!/usr/bin/env python
import subprocess
p = subprocess.Popen(["git", "log", "--format='%s'"], stdout=subprocess.PIPE)
out, err = p.communicate()
# Keep going until we don't find a "fixup! "
fixup_count = 0
max_list_size = 10
commits = out.split('\n')[:max_list_size]
/* myfile.c */
#include<stdio.h>
/* template.html */
<pre>{% include "myfile.c" %}</pre>
@joequery
joequery / environ.c
Created December 11, 2012 20:37
Safely using getenv with snprintf in C
#include <stdlib.h>
#include <stdio.h>
#define BUFSIZE 80
int main(){
char *cwd1;
char cwd2[BUFSIZE];
int result;
// Get the current working directory. This is vulnerable to buffer
@joequery
joequery / gist:3894914
Created October 15, 2012 19:57
Divide and conquer approach to finding index of largest element in a list.
# Yay school.
def find_largest(mylist):
if len(mylist) == 1:
return 0
elif len(mylist) == 2:
if mylist[0] > mylist[1]:
return 0
else:
return 1
else:
# Redirect everything to the main site.
server {
server_name www.mysite.com;
return 301 http://mysite.com$request_uri;
}
server {
server_name mysite.com;
location / { try_files $uri @flaskapp; }
location @flaskapp {
@joequery
joequery / gist:3813678
Created October 1, 2012 18:49
C errors
(Precise)~/lab/c$ gcc -std=c99 -Wall ex2.c -o ex2.o
ex2.c: In function ‘splitString’:
ex2.c:4:5: warning: implicit declaration of function ‘strlen’ [-Wimplicit-function-declaration]
ex2.c:4:15: warning: incompatible implicit declaration of built-in function ‘strlen’ [enabled by default]
ex2.c:10:9: warning: implicit declaration of function ‘isdigit’ [-Wimplicit-function-declaration]
ex2.c:25:5: warning: implicit declaration of function ‘sprintf’ [-Wimplicit-function-declaration]
ex2.c:25:5: warning: incompatible implicit declaration of built-in function ‘sprintf’ [enabled by default]
ex2.c:25:5: warning: format ‘%s’ expects argument of type ‘char *’, but argument 4 has type ‘char (*)[40]’ [-Wformat]
ex2.c:26:5: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
ex2.c:26:5: warning: incompatible implicit declaration of built-in function ‘printf’ [enabled by default]
@joequery
joequery / gist:3669934
Created September 7, 2012 21:42
mrbc segfault on syntax error
This file has been truncated, but you can view the full file.
Starting program: /Users/jmccullough/Sites/github/mruby/bin/mrbc -c /web/github/mrbc-playground/rubyfile.rb
Reading symbols for shared libraries +. done
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00007fff5f3ffff8
0x00000001000340f3 in sym_hash_func (mrb=0x100800000, s=Cannot access memory at address 0x7fff5f3ffff8
) at symbol.c:22
22 {
#0 0x00000001000340f3 in sym_hash_func (mrb=0x100800000, s=Cannot access memory at address 0x7fff5f3ffff8
) at symbol.c:22