Skip to content

Instantly share code, notes, and snippets.

View mejibyte's full-sized avatar

Andrés Mejía mejibyte

View GitHub Profile
#include <iostream>
using namespace std;
int main (){
int a, b;
while (cin >> a >> b) {
cout << a + b << endl;
}
return 0;
}
@mejibyte
mejibyte / gist:1994162
Created March 7, 2012 16:20
Counting inversions with coordinate compression
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
@mejibyte
mejibyte / gist:1953239
Created March 1, 2012 21:08
Upstart script to start nginx on Ubuntu
description "nginx http daemon"
start on runlevel [2]
stop on runlevel [016]
env NGINX_BIN=/usr/sbin/nginx
console owner
pre-start exec $NGINX_BIN -t
@mejibyte
mejibyte / gist:1947534
Created March 1, 2012 05:30
Solution to Digital Roulette, from Colombian National Programming Contest 2011
// Code written by Andrés Mejía
using namespace std;
#include <iostream>
#include <vector>
#include <set>
int main(){
int n, m;
while (cin >> n >> m) {
if (n == 0 and m == 0) break;
@mejibyte
mejibyte / gist:1726814
Created February 3, 2012 00:52
Solution to problem "Game with the Keyboard". This times out on case #30.
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
@mejibyte
mejibyte / gist:1680000
Created January 26, 2012 00:30
Solution to 10806 - Dijkstra, Dijkstra from UVa
// Problem statement: http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1747
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
@mejibyte
mejibyte / gist:1679972
Created January 26, 2012 00:22
Solution to 3518 - Guards from Live Archive
// Problem statement: http://livearchive.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=1519
using namespace std;
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
@mejibyte
mejibyte / backtrace.txt
Created January 3, 2012 03:29
Why do you define an instance method in a Rails mailer and then call a class method?
ruby-1.9.2-p290 :005 > Norman.welcome_email
NoMethodError: undefined method `asdf?' for nil:NilClass
from /Users/wack-a-mole/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.3/lib/active_support/whiny_nil.rb:48:in `method_missing'
from /private/tmp/bang/app/mailers/norman.rb:5:in `welcome_email'
from /Users/wack-a-mole/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/abstract_controller/base.rb:167:in `process_action'
from /Users/wack-a-mole/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/abstract_controller/base.rb:121:in `process'
from /Users/wack-a-mole/.rvm/gems/ruby-1.9.2-p290/gems/actionpack-3.1.3/lib/abstract_controller/rendering.rb:45:in `process'
from /Users/wack-a-mole/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.3/lib/action_mailer/old_api.rb:65:in `process'
from /Users/wack-a-mole/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.3/lib/action_mailer/base.rb:474:in `process'
from /Users/wack-a-mole/.rvm/gems/ruby-1.9.2-p290/gems/actionmailer-3.1.3/lib/action_mailer/base.rb:469:in `i
@mejibyte
mejibyte / val_lista.rb
Created December 23, 2011 00:15 — forked from nhocki/val_lista.rb
Validators for the training contest held on Dec. 22
#!/usr/bin/env ruby
require 'scanf'
if ARGV.size < 3
puts "Usage: #{__FILE__} <testdata.in> <program.out> <testdata.out>"
exit 1
end
def wrong_answer(reason)