Skip to content

Instantly share code, notes, and snippets.

View charles-l's full-sized avatar
👾
making games

Charles charles-l

👾
making games
View GitHub Profile
@charles-l
charles-l / generate_ctags.sh
Last active August 29, 2015 14:05
Generates ctags for libraries included at the top of C/C++ files
# Generates ctags for libraries included at the top of C/C++ files
# Requires ctags.
echo "Looking for *.c, *.h, *.cpp, *.hpp"
files=()
for i in $(grep -sroh '#include [<|"].*["|>]' *.c *.h *.cpp *.hpp | sort | uniq)
do
if [[ $i != "#include" ]]
then
FILENAME=$(echo "${i:1:(${#i}-2)}")
if [[ $(echo ${i:0:1}) == '"' ]]
@charles-l
charles-l / makefile
Last active August 29, 2015 14:11
Generic, minimal makefile that should work in most situations
LIBS="libname1 libname2"
IGNOREFILES := file1.c file2.c
BIN=binname
CC=gcc-4.9
###########################################################
#### NOTHING SHOULD NEED TO BE CHANGED BELOW THIS LINE ####
###########################################################
# Compiler options
@charles-l
charles-l / diff.rb
Last active August 29, 2015 14:13
LCS Algorithm Visualization
require 'curses'
include Curses
str1 = "hello my name is jake"
str2 = "mah name is greg"
init_screen
start_color
crmode
noecho
@charles-l
charles-l / diff.rb
Created January 19, 2015 01:15
simple diffing in ruby
str1 = "hello my name is jake"
str2 = "mah name is greg"
def printdiff(c, x, y, i, j)
return if c.nil?
if i > 0 and j > 0 and x[i] == y[j]
printdiff(c,x,y,i-1,j-1)
puts " " + x[i] unless x[i].nil?
elsif j > 0 and (i == 0 or c[i][j-1] >= c[i-1][j])
printdiff(c,x,y,i,j-1)
@charles-l
charles-l / sql_generate.rb
Created September 23, 2015 15:35
SQL generation for school project
# Ruby, Generate sql PLZ
require 'faker' # faker gem used to generate names/addresses/phone numbers
def gen_sql(tname, v)
id = 1
10.times do
s = "INSERT INTO #{tname} (#{v.keys.join(",")}) VALUES ("
o = []
v.values.each do |a|
if a == :id
@charles-l
charles-l / bwop.vim
Created November 3, 2015 02:07
Very simple color scheme (only highlights comments/strings)
hi clear
set background=dark
if exists("syntax_on")
syntax reset
endif
let g:colors_name = "bwop"
hi Normal ctermfg=7 ctermbg=0
hi Directory ctermfg=gray
hi Search ctermfg=white ctermbg=blue
#!/usr/bin/env python
import gdb
class ListPrintCommand(gdb.Command):
"""print atoms"""
def __init__(self):
super(ListPrintCommand, self).__init__("print-atom",
gdb.COMMAND_DATA, gdb.COMPLETE_SYMBOL)
@charles-l
charles-l / exploit.c
Last active April 14, 2016 05:34
exploit to solve pwn1 in the sctf challenge
#include <stdio.h>
// TO RUN EXPLOIT (this file just generates the junk needed to overflow to the return address):
// cc exploit.c; ./a.out | nc problems2.2016q1.sctf.io 1337
int main() {
// EIP points to the current stack frame (so we want it to point at get_flag)
//
// We can do this by overwriting the old return address with the address for get_flag
// (which you can get by running `pd 1 @ sym.get_flag` in radare)
@charles-l
charles-l / send_data_through_pipe.c
Last active April 30, 2016 00:58
Simple C program to send data through one end of a pipe, to a command, then read it back in.
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
// p pp
// (input - sent to first pipe) | tr a b | (output - read back in)
int main (void) {
int p[2];
@charles-l
charles-l / main.lua
Last active October 29, 2016 18:57
End of tutorial 1 for the polished platformer series
bump = require 'bump'
local world = bump.newWorld()
local level = {elems = {}}
function level:addElem(x, y, w, h, drawLambda)
local t = {draw = drawLambda}
world:add(t, x, y, w, h)
table.insert(self.elems, t)