Skip to content

Instantly share code, notes, and snippets.

View w00lf's full-sized avatar

Mikhail T w00lf

View GitHub Profile
@w00lf
w00lf / game_theory.java
Created August 29, 2013 09:11
*********Теория игр********* http://acmp.ru/index.asp?main=task&id_task=54
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] argv) throws IOException,Exception{
new Main().run();
}
PrintWriter pw;
@w00lf
w00lf / streamTokenizer.java
Created August 29, 2013 14:51
StreamTokenizer parse example
sc = new StreamTokenizer(new BufferedReader(new FileReader("input.txt")));
sc.wordChars( 44, 46 );
for (int i = 0; i < 10; i++) {
int token = sc.nextToken();
switch (token) {
case StreamTokenizer.TT_EOF:
System.out.println("End of File encountered.");
break;
case StreamTokenizer.TT_EOL:
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
public static void main(String[] argv) throws IOException,Exception{
new Main().run();
}
@w00lf
w00lf / spiral_rude.java
Created September 2, 2013 14:19
************Спираль*********** http://acmp.ru/index.asp?main=task&id_task=196
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
public static void main(String[] argv) throws IOException,Exception{
new Main().run();
}
@w00lf
w00lf / spiral_python_st.java
Created September 3, 2013 08:12
**************Спираль************* http://acmp.ru/index.asp?main=task&id_task=196 - таже задача, сильно отрефакторенный прмиер на основе кода python.
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
public static void main(String[] argv) throws IOException,Exception{
new Main().run();
}
@w00lf
w00lf / snake.java
Created September 3, 2013 10:51
**********Змейка************ http://acmp.ru/index.asp?main=task&id_task=197
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main{
public static void main(String[] argv) throws IOException,Exception{
new Main().run();
}
@w00lf
w00lf / minimum_notation.java
Created September 3, 2013 14:33
****************Наименьшая система счисления**************** http://acmp.ru/index.asp?main=task&id_task=315
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] argv) throws IOException,Exception{
new Main().run();
}
public void run() throws IOException,Exception{
@w00lf
w00lf / classic_hard.rb
Created October 28, 2013 08:21
Пример сложного запроса с подзапросом, выбираем номера книжек раздела, после чего выбираем авторов, книжки у которых иданы и принадлежат типу и номер входит в номера книжек раздела
def self.for_classic(compilation = nil)
if compilation.nil?
classic_ids_query = sprintf('SELECT "books".id FROM "books"
INNER JOIN "books_products" ON "books_products".book_id = "books".id
INNER JOIN "products" ON "products".id = "books_products".product_id
WHERE (products.id = %d)
AND ("books"."status" IN (%s, %s))', Product.classic_product.id, "E'published'", "E'republishing'")
else
classic_ids_query = sprintf('SELECT "books".id FROM "books"
INNER JOIN "books_compilations" ON "books".id = "books_compilations".book_id
@w00lf
w00lf / sql_rocket
Created December 12, 2013 19:40 — forked from boblail/sql_rocket
#!/usr/bin/env ruby
# encoding: utf-8
# https://gist.github.com/boblail/5587579
require 'benchmark'
require 'nokogiri'
require 'progressbar'
require 'tempfile'
class SqlRocket < Nokogiri::XML::SAX::Document
@w00lf
w00lf / parse_xml.rb
Created January 22, 2014 07:13
Filling tables with objects from xml, with forked insertion and also creation of dump for fast insert.
namespace :fias do
namespace :parse_xml do
class DumpCreator
# creates psql dump from template
attr_reader :target_file, :current_attributes
def initialize(target_file)
@target_file = target_file
target_file = File.open(target_file, 'a')
@stack = []