Skip to content

Instantly share code, notes, and snippets.

View stevepm's full-sized avatar
🏠
Working from home

Steve stevepm

🏠
Working from home
View GitHub Profile
@stevepm
stevepm / gist:1756809
Created February 7, 2012 02:47
java hw
import java.util.Scanner;
public class Driver {
private int age, carValue, tickets;
Scanner in;
public Driver(){
this.in = new Scanner(System.in);
@stevepm
stevepm / gist:1771209
Created February 8, 2012 17:13
scrape
<?php
error_reporting(E_ERROR | E_PARSE);
$dom = new DOMDocument();
$dom->loadHTMLFile('http://www.xbox360achievements.org/games/retail/');
$xml = simplexml_import_dom($dom);
$links = $xml->xpath('//table/tr/td/a');
for($i=30;$i<count($links);$i++):
?>
<a target="_blank" href="http://www.xbox360achievements.org/games/retail/<?php echo $links[$i]['href']; ?>"><?php echo $links[$i]['href']; ?></a><br/>
<?php
<?php
include("simple_html_dom.php");
// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');
// Find all images
/*foreach($html->find('img') as $element)
echo $element->src . '<br>';
// Find all links
<?php
/**
* Created by JetBrains PhpStorm.
* User: mint
* Date: 9/4/13
* Time: 1:41 AM
* To change this template use File | Settings | File Templates.
*/
echo "hello";
@stevepm
stevepm / app.rb
Created April 14, 2014 19:20
Application File
require 'sinatra/base'
require 'rack-flash'
class App < Sinatra::Application
enable :sessions
use Rack::Flash
helpers do
def h(text)
class Dogs
POOR = (0..5).to_a.sample
AVERAGE = (6..10).to_a.sample
EXCELLENT = (11..15).to_a.sample
def initialize
joe = {
:name => {:first => "Joe", :last=> "Smith"},
:owner_quality => EXCELLENT
}
@stevepm
stevepm / http_response.rb
Last active August 29, 2015 14:01
HttpResponse
require 'fileutils'
class HttpResponse
def initialize(text)
@text = text
@headers = @text.split("\n\n").first
@body = @text.split("\n\n")[1]
end
def headers
# in spec/support/omniauth_macros.rb
module OmniauthMacros
def mock_auth_hash
# The mock_auth configuration allows you to set per-provider (or default)
# authentication hashes to return during integration testing.
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
'uid' => '123545',
'user_info' => {
'name' => 'mockuser',
{
from: 0,
size: 150,
query: {
filtered: {
query: {
bool: {
should: [
function_score: {
query: {
@stevepm
stevepm / elasticsearch.rb
Last active August 29, 2015 14:02
Elastic search query
settings index: {number_of_shards: 1} do
mappings dynamic: 'false' do
indexes :name, analyzer: 'standard', index_options: 'offsets'
indexes :description, analyzer: 'standard', index_options: 'offsets'
indexes :total_downloads, type: 'long'
end
end
def search(query)
__elasticsearch__.search(