Skip to content

Instantly share code, notes, and snippets.

View KWKdesign's full-sized avatar

Kevin Klingelhoefer KWKdesign

View GitHub Profile
@KWKdesign
KWKdesign / sources.list
Last active January 4, 2016 21:19
Setup Apt on Debian Wheezy
deb http://http.debian.net/debian wheezy main
deb-src http://http.debian.net/debian wheezy main
deb http://security.debian.org/ wheezy/updates main
deb-src http://security.debian.org/ wheezy/updates main
deb http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main
deb-src http://apt.postgresql.org/pub/repos/apt/ wheezy-pgdg main
deb http://packages.dotdeb.org wheezy all
@KWKdesign
KWKdesign / schemaverse-svg.pl
Last active August 29, 2015 13:56
Schemaverse Ship Visualizer
#! /usr/bin/perl
use 5.010;
use strict;
use warnings;
use Data::Dump qw/dd ddx dump/;
use DBI;
use SVG;
use Template;
use File::Temp qw/tempfile/;
@KWKdesign
KWKdesign / sv_trophies.sql
Last active August 29, 2015 14:03
Schemaverse: Trophies Last Round
select name, weight, description
from player_trophy, round_seq, trophy
where 1=1
and player_id = get_player_id(session_user)
and round = last_value-1
and id = trophy_id
;
@KWKdesign
KWKdesign / sv_last_tic_duration.sql
Last active August 29, 2015 14:03
Schemaverse: Last Tic Duration
select
( select toc from my_events
where public and action = 'TIC'
and tic = ( select last_value-1 from tic_seq )
)::time -
( select toc from my_events
where public and action = 'TIC'
and tic = ( select last_value-2 from tic_seq )
)::time
;
@KWKdesign
KWKdesign / attack_heatmap.sql
Last active August 29, 2015 14:05
Schemaverse: Attack Heatmap SQL
with max_xy as (
select greatest(
max( abs( location_x ) ),
max( abs( location_y ) )
) v
from planets
),
scale as (
select m * ceil( v / m ) scale from (
select 10 ^ floor( log( v ) ) m, v
@KWKdesign
KWKdesign / ships_heatmap.sql
Last active August 29, 2015 14:05
Schemaverse: Ships Heatmap SQL
with max_xy as (
select greatest(
max( abs( location_x ) ),
max( abs( location_y ) )
) v
from planets
),
scale as (
select m * ceil( v / m ) scale from (
select 10 ^ floor( log( v ) ) m, v
@KWKdesign
KWKdesign / circle_map.sql
Last active August 29, 2015 14:12
SV Circle Map Creation
-- while ( select count(1) from planet ) < ( select count(1) from player ) * 1.05 loop
while ( select count(1) from planet ) < 2000 loop
for new_planet in
select nextval( 'planet_id_seq' ) as id,
case ( random() * 11 )::integer % 12
when 0 then 'Aethra_' || generate_series
when 1 then 'Mony_' || generate_series
when 2 then 'Semper_' || generate_series
when 3 then 'Voit_' || generate_series
when 4 then 'Lester_' || generate_series
@KWKdesign
KWKdesign / packed_circle_map.sql
Last active August 29, 2015 14:12
Schemaverse Packed Circle Map Creation
select
100000::numeric radius,
0::numeric y,
0::numeric a,
0::numeric b,
( null )::point ta,
( null )::point tb,
0::numeric angle,
1::int i,
0::int cnt,
@KWKdesign
KWKdesign / rot13.sql
Created January 10, 2015 23:06
Postgres ROT13
create or replace function pg_temp.rot13( string text )
returns text as $rot13$
begin
return translate( string, 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz', 'NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm' );
end $rot13$ language plpgsql;
@KWKdesign
KWKdesign / schemaverse_example.sql
Last active August 29, 2015 14:13
Schemaverse Example Fleet Script
insert into my_fleets ( name ) values ( 'main' );
update my_fleets set
script_declarations = '
my_player_id int := get_player_id( session_user );
cash bigint;
ship record;
planet record;
target record;
',