Skip to content

Instantly share code, notes, and snippets.

View delucas's full-sized avatar

Lucas Videla delucas

  • Buenos Aires, Argentina
View GitHub Profile
@salamander2
salamander2 / hexgame.java
Created December 18, 2012 17:03
Hexagonal Grid in Java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**********************************
This is the main class of a Java program to play a game based on hexagonal tiles.
The mechanism of handling hexes is in the file hexmech.java.
Written by: M.H.
Date: December 2012
def countChange(money: Int, coins: List[Int]): Int =
if (money < 0 || coins.isEmpty)
0
else if (money == 0)
1
else
countChange(money - coins.head, coins) + countChange(money, coins.tail)
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active June 1, 2024 14:11
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@ravasthi
ravasthi / _config.yml
Created February 15, 2012 08:59
Multiple authors on Jekyll
authors:
hanzou:
name: Hanzou Hattori
display_name: Hanzou
gravatar: c66919cb194f96c696c1da0c47354a6a
email: hanzou@company.com
web: http://company.com
twitter: company
github: hhattori
jorgen:
@wilmoore
wilmoore / ie6winxp.vm.md
Created January 31, 2012 17:32
Windows 7 VM w/ IE (Virtualbox)

This will provide a much faster and favorable experience VS RDC over network (or worse, the internet). It also gives you free reign to do whatever else you might want to do on windows (which for me isn't much, but a nice-to-have none-the-less).

The following list of commands will get you a free (microsoft sponsored) Windows XP VM environment with IE6 installed. The password is "Password1". When you first login, you will be asked to activate the OS. Do this immediately over the internet. You will get 90 days of activation. Once this runs out, activate the snapshot called "The initial VM state" to go back in time.

% mkdir -p ~/.vm/hdds/windows/winxp-ie6/
% cd !$

% wget http://download.microsoft.com/download/B/7/2/B72085AE-0F04-4C6F-9182-BF1EE90F5273/Windows_XP_IE6.exe
% unrar e Windows_XP_IE6.exe
@jcasimir
jcasimir / friendly_urls.markdown
Created September 11, 2011 15:48
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@nhocki
nhocki / gist:1095522
Created July 20, 2011 18:11 — forked from croaky/gist:1089598
Transfer data from production to staging on Heroku
heroku addons:add pgbackups --remote staging
heroku addons:add pgbackups --remote production
heroku pgbackups:capture --remote production
heroku pgbackups:restore DATABASE `heroku pgbackups:url --remote production` --remote staging
@markysharky70
markysharky70 / gist:1019289
Created June 10, 2011 17:20
Copy your production database to your staging database hosted on Heroku
1) backup production database:
heroku pgbackups:capture --expire --remote production
2) obtain url string to backup from step 1:
heroku pgbackups:url --app production_app_name --remote production_app_branch_name
3) transfer backup from production to staging app:
heroku pgbackups:restore DATABASE 'production_app_backup_url_string_from_step_2' --app production_app_name --app staging_app_branch_name
@mattetti
mattetti / gist:1015948
Created June 9, 2011 02:44
some excel formulas in Ruby
module Excel
module Formulas
def pmt(rate, nper, pv, fv=0, type=0)
((-pv * pvif(rate, nper) - fv ) / ((1.0 + rate * type) * fvifa(rate, nper)))
end
def ipmt(rate, per, nper, pv, fv=0, type=0)
p = pmt(rate, nper, pv, fv, 0);
ip = -(pv * pow1p(rate, per - 1) * rate + p * pow1pm1(rate, per - 1))
(type == 0) ? ip : ip / (1 + rate)
@miceno
miceno / gist:787640
Created January 20, 2011 09:33
Groovy HTML DSL example
// def writer = new FileWriter('markup.html')
def writer = new StringWriter()
def html = new groovy.xml.MarkupBuilder(writer)
html.html {
head { title 'Constructed by MarkupBuilder' }
body {
h1 'What can I do with MarkupBuilder?'
form (action:'whatever') {