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 / 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 / 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 / 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 / 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 / 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 / main.lua
Created July 19, 2014 19:27
Cocoa Rectangle Drawing Example (with Lua objc FFI)
-- This gist uses http://luapower.com/objc.html as an FFI. I think it works on it's own, but I would recommend
-- getting the whole LuaPower project, because all the libraries rock.
--
-- This script will open a window that displays two rectangles. One red and one blue.
local glue = require'glue'
local objc = require'objc'
local ffi = require'ffi'
local pp = require'pp'
@charles-l
charles-l / gif2spritesheet.sh
Created April 26, 2014 16:13
Converts an animated gif to a spritesheet using ImageMagick
# Converts an animated gif to a spritesheet using ImageMagick
file_name=$(echo $1 | sed 's/\(.*\)\..*/\1/')
montage $1 -tile x1 -geometry '1x1+0+0<' -alpha On -background "rgba(0, 0, 0, 0.0)" -quality 100 $file_name.png