Skip to content

Instantly share code, notes, and snippets.

import java.io.*;
import java.util.*;
/*
Word Count Engine
Implement a document scanning function wordCountEngine, which receives a string document and returns a list of all unique words in it and their number of occurrences, sorted by the number of occurrences in a descending order. If two or more words have the same count, they should be sorted according to their order in the original sentence. Assume that all letters are in english alphabet. You function should be case-insensitive, so for instance, the words “Perfect” and “perfect” should be considered the same word.
The engine should strip out punctuation (even in the middle of a word) and use whitespaces to separate words.
Analyze the time and space complexities of your solution. Try to optimize for time while keeping a polynomial space complexity.
sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get -y install unzip python3-pip python3-setuptools python3-dev build-essential libssl-dev libffi-dev xvfb
sudo pip3 install --upgrade pip
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
sudo dpkg-reconfigure locales
pip3 install --upgrade pip
package tasks
import (
"fmt"
"github.com/asdine/storm"
"github.com/asdine/storm/q"
)
// Init storm
var DB *storm.DB
DB, err := storm.Open("my_storm.db")
Failures:
1) User adds a note to a dealer in T-1000 note is added and shown on the dealer page
Failure/Error: go_to_dealer_page dealer.name
Capybara::ElementNotFound:
Unable to find link "Dealers"
# ./spec/support/helpers/ember_app_navigation/dealer.rb:11:in `go_to_dealers_page'
# ./spec/support/helpers/ember_app_navigation/dealer.rb:5:in `go_to_dealer_page'
# ./spec/features/t1000/notes_spec.rb:9:in `block (2 levels) in <top (required)>'
print "oi"
def square(n):
return n * n
def abs(n):
if n > 0:
return n
elif n < 0:
return -n
require "rubygems"
require "sinatra"
require "erb"
require "digest/md5"
require "uri"
require "data_mapper"
set :static, true
set :public_folder, "#{File.dirname(__FILE__)}/public"
set :views, "#{File.dirname(__FILE__)}/views"
C = Class.new do
def has?(methods)
!!methods.split(".").inject(self) do |object, method|
object.respond_to?(method) && object.send(method)
end
end
end
c = C.new
c.has?("methods") # => true
@dlt
dlt / gist:1515236
Created December 23, 2011 20:07
whyyyyyyy?
class Hash
def [](k)
fetch(k) do
super[k.intern] || super[k.to_s]
end
end
end
{ key: 'EXPECTED'}['key']
saved = 0
not_saved = 0
Product.all.to_a.select do |p|
p.image && p.image.url
end.each do |p|
begin
temp = Tempfile.new("foo")
temp.puts \
Mongo::GridFileSystem.new(Mongoid.database).
@dlt
dlt / gist:1421359
Created December 2, 2011 01:56
Why is 'y' defined?
ruby-1.9.2-p180 :001 > if 1 then x = 1 else y = 0 end
=> 1
ruby-1.9.2-p180 :002 > y
=> nil
ruby-1.9.2-p180 :003 > x
=> 1
ruby-1.9.2-p180 :004 > z
NameError: undefined local variable or method `z' for main:Object
from (irb):4
from /home/dlt/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'