Skip to content

Instantly share code, notes, and snippets.

View DemitryT's full-sized avatar

Demitry Toumilovich DemitryT

View GitHub Profile
@DemitryT
DemitryT / crawler.rb
Created August 16, 2011 19:19
Simple ruby program to crawl a specific page for links
require 'rubygems'
require 'anemone'
#!/usr/bin/env ruby
# To use the anemone gem to crawl website make sure these are installed:
# 1) Redis (>= 2.0.0)
# 2) MongoDB
# 3) TokyoCabinet
# 4) PStore
# crawl website for specific info for Hazzo marketing purposes
@DemitryT
DemitryT / mechanize.rb
Created August 16, 2011 19:20
Ruby program to scrape specific information of a web page
require 'rubygems'
require 'nokogiri'
require 'open-uri'
# Get a Nokogiri::HTML:Document for the page we’re interested in...
url = 'http://www.groupon.com/denver/deals/next-door-lounge'
doc = Nokogiri::HTML(open(url)) #do |config|
doc.at_css("ul#counter li.ended").text
# config.noerror
@DemitryT
DemitryT / HowEasy.java
Created August 18, 2011 21:42
Simple problem I solved using Java, on www.topcoder.com, which was to evaluate the difficulty of a problem based on its word length.
import java.util.*;
import java.util.Arrays;
public class HowEasy{
public int pointVal(String problemstatement){
//problemstatement is a string containing between 1 - 50 letters, numbers, spaces or periods
String[] words = problemstatement.split(" "); //seperates all words from problem statement with space as seperator
int totalWords = words.length;
@DemitryT
DemitryT / application.js
Created August 18, 2011 21:52
AJAX feature to retrieve user information (from my personal website, which I'm writing in PHP)
jQuery(document).ready(function()
{
var hideDelay = 500;
var userID;
var hideTimer = null;
// One instance that's reused to show info for the current person
var container = jQuery('<div id="personPopupContainer">'
+ '<table width="" border="0" cellspacing="0" cellpadding="0" align="center" class="personPopupPopup">'
+ '<tr>'
@DemitryT
DemitryT / _coupon_block.html.haml
Created August 18, 2011 22:01
"Re-send a gift coupon" feature I implemented on a Ruby on Rails application at my last job
# only including what I helped write below
.coupon_list
- array_of_coupons.each do |coupon|
%div
- if redeemed
%span.cross_out
= "#" + coupon.uid
%span.green
= link_to (coupon.user_redeemed ? "Mark as New" : "Mark as Used"), '#', :class => 'user_redeemed', :rel => toggle_user_redeemed_coupon_path(coupon)
@DemitryT
DemitryT / walkscore.rb
Created January 4, 2012 22:10
walkscore.rb
require 'httparty'
class Walkscore
include HTTParty
attr_accessor :api_key, :property
def initialize(api_key, property)
self.api_key = api_key
self.property = property
@DemitryT
DemitryT / process_kill
Created May 15, 2012 16:22
handy command to kill a process in one line
ps aux|grep script/rails|grep -v grep|awk '{print $2}'|xargs kill -9
@DemitryT
DemitryT / users_controller.rb
Created June 4, 2012 20:03
users_controller.rb
if current_company.has_rentals?
property_ids = []
@lead.rental_saved_searches.each do |rss|
if rss.rental_search.send(current_company.rental_property_type) == true
@lead_details[:saved_searches][:rentals] << rss
end
end
if current_company.rentals_lead_plan.to_sym == :one
@lead.favorite_rental_properties.each do |frp|
if frp.rental_property_type == current_company.rental_property_type
@DemitryT
DemitryT / sql.sql
Created July 12, 2012 20:39
sql.sql
SELECT `companies`.* FROM `companies` INNER JOIN `company_services`
ON `company_services`.`company_id` = `companies`.`id`
WHERE (company_services.id is not null) AND (active = 1 AND staging = 0 AND trulia_feed = 1);
@DemitryT
DemitryT / admin.js
Created August 29, 2012 14:10
admin.js
function updateMapMarkerOnShowAddressChange() {
// added the if statement below
if($("setting_rentals_details_map_marker_box")) {
var boxRadioButton = $("setting_rentals_details_map_marker_box");
var initialMapMarkerBox = boxRadioButton.checked;
}
var rentAddressCheckbox = $('setting_show_rental_address');
var pinRadioButton = $("setting_rentals_details_map_marker_pin");
// added the if statement below