Skip to content

Instantly share code, notes, and snippets.

@joequery
joequery / gist:3418565
Created August 21, 2012 19:31
Tab or complete
"Use TAB to complete when typing words, else inserts TABs as usual.
function! Tab_Or_Complete()
if col('.')>1 && strpart( getline('.'), col('.')-2, 3 ) =~ '^\w'
return "\<C-N>"
else
return "\<Tab>"
endif
endfunction
inoremap <Tab> <C-R>=Tab_Or_Complete()<CR>
@joequery
joequery / gist:3418841
Created August 21, 2012 19:54
Vim Toggle Relative Line Numbers
" use Ctrl+L to toggle the line number counting method
function! g:ToggleNuMode()
if &nu == 1
set rnu
else
set nu
endif
endfunction
nnoremap <silent><C-L> :call g:ToggleNuMode()<cr>
@joequery
joequery / gist:3421153
Created August 22, 2012 01:20
Postfix Calculator
// Implement a post-fix calculator using a stack.
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
#define MAX_ELEMENTS 100
#define ROGUE_VALUE -99999
typedef int stackdata_t;
typedef struct{
@joequery
joequery / gist:3425222
Created August 22, 2012 12:42
Ghetto Autotest
#!/bin/bash
# Our ghetto auto-testish thing. User presses any key to test,
# Ctrl-C to get out. Make this file executable, place in your path, and run in
# your Ruby project's directory. Assumes your tests are located in spec/
# Technically 100% more convenient than up+enter! ;)
function hold(){
read -n 1 -s
}
@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
@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]
# 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: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:
@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
/* myfile.c */
#include<stdio.h>
/* template.html */
<pre>{% include "myfile.c" %}</pre>