Skip to content

Instantly share code, notes, and snippets.

@kevindoran
kevindoran / requestHandler.xml
Last active December 12, 2015 04:18
An example Solr search request handler definition.
<requestHandler name="/broadQuery" class="solr.SearchHandler">
<lst name="defaults">
<str name="defType">edismax</str> <!-- The search parser to use. -->
<str name="wt">xml</str> <!-- Output type. -->
<str name="fl">auction_id title</str> <!-- The fields to list in the search response -->
<str name="qf">Title^2 Feature</str> <!-- The fields (and their weightings) to search in.-->
<str name="rows">100</str> <!-- The number of results to return. -->
<str name="pf">Title^4 Feature^2</str> <!-- Phrase field (and their weightings). Fields to search for closely located matches. -->
<str name="ps">0</str> <!-- Phrase slop. How many tokens apart must words be to be able to qualify as a phrase-->
<str name="echoParams">all</str> <!-- Print the search settings in the search results. Just a handy feature -->
@kevindoran
kevindoran / Search.java
Created February 9, 2013 01:31
SolrJ example
public class SimpleSolrSearch {
private String solrUrl = "http://192.168.1.103:8983/solr/auctions";
private SolrServer server;
public SimpleSolrSearch() {
server = new HttpSolrServer(solrUrl);
}
public Collection<Integer> search(String searchTerms, String category, BigDecimal maxBidAmount) throws SolrServerException {
SolrQuery query = new SolrQuery();
@kevindoran
kevindoran / socketClient.py
Last active December 7, 2021 21:25
A simple Python script to send messages to a sever over Bluetooth using Python sockets (with Python 3.3 or above).
"""
A simple Python script to send messages to a sever over Bluetooth using
Python sockets (with Python 3.3 or above).
"""
import socket
serverMACAddress = '00:1f:e1:dd:08:3d'
port = 3
s = socket.socket(socket.AF_BLUETOOTH, socket.SOCK_STREAM, socket.BTPROTO_RFCOMM)
@kevindoran
kevindoran / socketServer.py
Last active March 23, 2021 18:42
A simple Python script to receive messages from a client over Bluetooth using Python sockets (with Python 3.3 or above).
"""
A simple Python script to receive messages from a client over
Bluetooth using Python sockets (with Python 3.3 or above).
"""
import socket
hostMACAddress = '00:1f:e1:dd:08:3d' # The MAC address of a Bluetooth adapter on the server. The server might have multiple Bluetooth adapters.
port = 3 # 3 is an arbitrary choice. However, it must match the port used by the client.
backlog = 1
@kevindoran
kevindoran / serverDifference.py
Last active December 16, 2015 11:38
Difference between the Bluetooth and Internet client-server applications.
# For the Server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(("192.168.1.17",50001)) # The Bluetooth MAC Address and RFCOMM port is replaced with an IP Address and a TCP port.
# For the Client
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(("192.168.1.17",50001))
@kevindoran
kevindoran / pyBluezServer.py
Last active November 6, 2022 23:39
A simple Python script to receive messages from a client over Bluetooth using PyBluez (with Python 2).
"""
A simple Python script to receive messages from a client over
Bluetooth using PyBluez (with Python 2).
"""
import bluetooth
hostMACAddress = '00:1f:e1:dd:08:3d' # The MAC address of a Bluetooth adapter on the server. The server might have multiple Bluetooth adapters.
port = 3
backlog = 1
@kevindoran
kevindoran / PyBluezClient.py
Last active January 30, 2023 19:42
A simple Python script to send messages to a sever over Bluetooth using PyBluez (with Python 2).
"""
A simple Python script to send messages to a sever over Bluetooth
using PyBluez (with Python 2).
"""
import bluetooth
serverMACAddress = '00:1f:e1:dd:08:3d'
port = 3
s = bluetooth.BluetoothSocket(bluetooth.RFCOMM)
@kevindoran
kevindoran / Dragon.java
Created June 1, 2013 02:51
Dragon class with inner speed calculator. This class is used to demonstrate aspects of Java serialization.
public class Dragon implements Serializable {
private static final long serialVersionUID = 1L;
private double wingSpan;
private String name;
private SpeedCalculator speedCalculator = new SpeedCalculator();
public Dragon(double wingSpan, String name) {
// Input checks. For example, insuring wing size is greater than zero.
this.wingSpan = wingSpan;
@kevindoran
kevindoran / Dragon.java
Created June 1, 2013 03:00
Dragon class. This class is used to demonstrate Java Serialization aspects.
public class Dragon implements Serializable {
private static final long serialVersionUID = 1L;
private double wingSpan;
private String name;
public Dragon(double wingSpan, String name) {
// Input checks. For example, insuring wing size is greater than zero.
this.wingSpan = wingSpan;
this.name = name;
@kevindoran
kevindoran / Dragon.java
Created June 1, 2013 03:03
Dragon class used to demonstrate security issues when using Java serialization.
public Dragon(double wingSpan, double name, SpeedCalculator speedCalculator) {
// There are no input checks this time!
this.wingSpan = wingSpan;
this.name = name;
this.speedCalculator = speedCalculator; // This is new!
}