Last active
May 23, 2016 20:25
-
-
Save granolocks/7275e514927034678c1c3f441ba6eb7b to your computer and use it in GitHub Desktop.
lets try to abuse sqlite for fun and profit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'data_mapper' | |
| require 'thread' | |
| werdz = %w{ | |
| The beet is the most intense of vegetables. The radish, admittedly, | |
| is more feverish, but the fire of the radish is a cold fire, the fire of | |
| discontent not of passion. Tomatoes are lusty enough, yet there runs through | |
| tomatoes an undercurrent of frivolity. Beets are deadly serious. Slavic | |
| peoples get their physical characteristics from potatoes, their smoldering | |
| inquietude from radishes, their seriousness from beets. The beet is the | |
| melancholy vegetable, the one most willing to suffer. You can't squeeze blood | |
| out of a turnip... The beet is the murderer returned to the scene of the | |
| crime. The beet is what happens when the cherry finishes with the carrot. The | |
| beet is the ancient ancestor of the autumn moon, bearded, buried, all but | |
| fossilized; the dark green sails of the grounded moon-boat stitched with | |
| veins of primordial plasma; the kite string that once connected the moon to | |
| the Earth now a muddy whisker drilling desperately for rubies. The beet was | |
| Rasputin's favorite vegetable. You could see it in his eyes | |
| }.uniq | |
| class DmTest | |
| include DataMapper::Resource | |
| property :id, Serial | |
| property :data, String | |
| end | |
| db_file = 'dmtest.db' | |
| DataMapper.setup(:default, "sqlite:#{db_file}") | |
| DataMapper.auto_upgrade! | |
| DataMapper.finalize | |
| @out = $stdout | |
| wthread = Thread.new do | |
| loop do | |
| begin | |
| 100.times do | |
| dmt = DmTest.new | |
| dmt.data = werdz.sample | |
| dmt.save | |
| end | |
| # @out.puts "created: #{dmt.id} #{dmt.data}" | |
| # @out.puts "w looped" | |
| # @out.puts "lastID: #{DmTest.last.id}" | |
| rescue => e | |
| @out.puts "ERROR IN WTHREAD" | |
| @out.puts e | |
| end | |
| end | |
| end | |
| rthread = Thread.new do | |
| loop do | |
| begin | |
| 100.times do | |
| werdz.each do |w| | |
| x = DmTest.all(data: w).count | |
| # @out.puts "#{w}: #{x}" | |
| end | |
| end | |
| # @out.puts "r looped" | |
| sleep 0.1 | |
| rescue => e | |
| @out.puts "ERROR IN RTHREAD" | |
| @out.puts e | |
| end | |
| end | |
| end | |
| uthread = Thread.new do | |
| loop do | |
| begin | |
| last_id = DmTest.last.id | |
| 100.times do | |
| x = DmTest.get(rand(last_id) + 1) | |
| d1 = x.data | |
| x.data = werdz.sample | |
| x.save | |
| # @out.puts "updated: #{x.id} #{d1} -> #{x.data}" | |
| end | |
| # @out.puts "u looped" | |
| sleep 0.1 | |
| rescue => e | |
| @out.puts "ERROR IN UTHREAD" | |
| @out.puts e | |
| end | |
| end | |
| end | |
| loop{sleep 1} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment