Thursday, 12 September 2013

Load JPEG image into a BlobField

Load JPEG image into a BlobField

I would like load JPEG image into a blob field, is it possible? I search a
lot but I don't find a clear answer.
I use this code:
var
BlobField : TBlobField;
Stream : TMemoryStream;
begin
BlobField := ClientDataSet1.FieldByName('image');
// Img is TImage and contain a JPEG image
Img.Picture.Graphic.SaveToStream(Stream);
Stream.Position := 0;
BlobField.LoadFromStream(Stream); // <-- Error: "Bitmap image is not
valid"
I have to use bitmap image?

Wednesday, 11 September 2013

jquery background image url failed

jquery background image url failed

This is not working ....
$("#news_all ul li").css("background", "transparent
url('../images/01.png') no-repeat");
but this is working
.news_all_item li {
background: url("../images/01.png") no-repeat scroll 0 0 transparent;
margin-bottom: 2%;
}
My html
<div class="news_all_item" id="news_all">
<ul>
<li><div class="news_item">Lorem Ipsum is simply dummy text of the
printing and typesettiLorem Ipsum is simply dummy
textlt;/divgt;lt;/ligt;
lt;ligt;lt;div class=news_itemgt;Lorem Ipsum is simply dummy text of
the printing and typesettiLorem Ipsum lt;/divgt;lt;/ligt;
lt;ligt;lt;div class=news_itemgt;Lorem Ipsum is simply dummy text of
the printing and typesettilt;/divgt;lt;/ligt;
lt;/ulgt;
lt;/divgt;
/code/pre

Is `a

Is `a

I was curious to see if I could use this a<b<c as a conditional without
using the standard a<b and b<c. So I tried it out and my test results
passed.
a = 1
b = 2
c = 3
assert(a<b<c) # In bounds test
assert(not(b<a<c)) # Out of bounds test
assert(not(a<c<b)) # Out of bounds test
Just for good measure I tried more numbers, this time in the negative
region. Where a, b, c = -10, -9, -8. The test passed once again. Even the
test suit at a higher range works a, b, c = 10, 11, 12. Or even a, b, c =
10, 20, 5.
And the same experiment done in C++. This was my mentality going into it:
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
a=10;
b=20;
c=5;
cout << ((a<b<c)?"True":"False") << endl; // Provides True (wrong)
cout << ((a<b && b<c)?"True":"False") << endl; // Provides False
(proper answer)
return 0;
}
I originally though that this implementation would be invalid since in
every other language I have come across would evaluate a boolean before it
would reach c. With those languages, a<b would evaluate to a boolean and
continuing the evaluation, b<c, would be invalid since it would attempt to
evaluate a boolean against a number (most likely throwing a compile time
error or falsifying the intended comparison). This is a little unsettling
to me for some reason. I guess I just need to be reassured that this is
part of the syntax. It would also be helpful to provide a reference to
where this feature is provided in the Python documentation so I can see to
what extent they provide features like this.

Does cout object remain a single instance, i.e. it never gets copied?

Does cout object remain a single instance, i.e. it never gets copied?

Is cout ever copied implicitly?
For example, is the cout object passed to the second overloaded operator
in the code below, and the cout object inside its implementation are the
same objects or is one a copy of cout?
My understanding is that the first implementation is correct because the
<< operator works for any ostream object, e.g. it will work for ofstream
objects for writing to files.
//First implementation
ostream& operator<<(ostream& os, const Date& dt)
{
os << dt.mo << '/' << dt.da << '/' << dt.yr;
return os;
}
//Second implementation
ostream& operator<<(ostream& os, const Date& dt)
{
cout << dt.mo << '/' << dt.da << '/' << dt.yr;
return cout;
}
//using second implementation on object date
cout<<date;

Creating reusable Django models

Creating reusable Django models

Having some trouble designing an application using Django models. More
specifically, I am trying to decide in which application a given model
should go.
A good example would be with a model where different analyses would be
performed on an object. For example, if I were doing an analysis on the
efficiency of a prostitution ring, I would have three models: Pimp, Whore,
and Client:
The pimp object would have a "stable" attribute which represents the
one-to-many relationship between the Pimp and his whores.
The Whore object would have a many-to-many relationship with the Client
object, or, there would be an additional "Trick" object, representing the
relationship between Whores and Clients.
If I wanted to analyze these objects in one way, i.e. seeing each whore's
percent time "occupied", this would be one simple application. But what if
I wanted to do additional analysis on these objects, i.e. see what whores
are the most "in demand"? It would make sense to me that each kind if
analysis belongs to an individual app, but then to which app do these
common objects belong?
Is there a common place where these common models should be stored? Should
all analyses be contained in one app?

Java Networking Console Spam

Java Networking Console Spam

I am trying to make a plugin for Bukkit, that will allow multiple servers
to talk to each other (send data over ip:port). I have got the basic code
working but when I reload the plugin the console gets spammed with this
java.net.SocketException: Socket is closed 2013-09-11 19:56:19 [SEVERE] at
java.net.ServerSocket.accept(Unknown Source) 2013-09-11 19:56:19 [SEVERE]
at com.github.dcsoftgit.multiserver.ReadThread.run(ReadThread.java:14)
This is my code for server1:
package com.github.dcsoftgit.multiserver;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
public class MultiServer extends JavaPlugin {
public static ServerSocket sock;
ReadThread t;
public void onEnable() {
t = new ReadThread();
try {
sock = new ServerSocket(4571);
} catch (IOException e) {
e.printStackTrace();
}
t.start();
getServer().getScheduler().scheduleSyncDelayedTask(this, new
Runnable() {
@Override
public void run() {
sendDataToSocket("Hello server 2");
}
});
}
public void onDisable() {
try {
sock.close();
} catch (IOException e) {
}
}
public static void sendDataToSocket(String data) {
Socket client;
try {
client = new Socket("127.0.0.1", 4572);
DataOutputStream ds = new
DataOutputStream(client.getOutputStream());
ds.writeUTF(data);
ds.close();
client.close();
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
and this is server2:
package com.github.dcsoftgit.multiserver;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
public class MultiServer extends JavaPlugin {
public static ServerSocket sock;
ReadThread t;
public void onEnable() {
t = new ReadThread();
try {
sock = new ServerSocket(4572);
} catch (IOException e) {
e.printStackTrace();
}
t.start();
getServer().getScheduler().scheduleSyncDelayedTask(this, new
Runnable() {
@Override
public void run() {
sendDataToSocket("Hello server 1");
}
});
}
public void onDisable() {
try {
sock.close();
} catch (IOException e) {
}
}
public static void sendDataToSocket(String data) {
Socket client;
try {
client = new Socket("127.0.0.1", 4571);
DataOutputStream ds = new
DataOutputStream(client.getOutputStream());
ds.writeUTF(data);
ds.close();
client.close();
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
this is the ReadThread class:
package com.github.dcsoftgit.multiserver;
import java.io.DataInputStream;
import java.io.IOException;
import java.net.Socket;
public class ReadThread extends Thread {
public void run(){
while (!isInterrupted()){
try {
//init the client
Socket client = MultiServer.sock.accept();
//Read the data
DataInputStream dis = new
DataInputStream(client.getInputStream());
String data = dis.readUTF();
System.out.println(data);
dis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@Override
public synchronized void start() {
super.start();
}
}
Using this code when I reload the plugin it calls onDisable() and then
onEnable(). When the server starts it only calls onEnable().

Print osm using mapfish printservlet war file in tomcat

Print osm using mapfish printservlet war file in tomcat

I have downloaded the war file of the mapfish print osm and deployed it in
the tomcat, and used the js files from
http://api.geoext.org/1.1/examples/print-preview-osm.html, but i'm having
an exception
org.mapfish.print.InvalidJsonValueException: spec.layers[0].type has an
invalid value: OSM
is it the right way to do to print the map or can anybody point me in
right direction..my code is:
Ext.onReady(function() {
// The PrintProvider that connects us to the print service
var printProvider = new GeoExt.data.PrintProvider({
url: "http://localhost:8000/print-servlet-1.1/pdf/print.pdf",
method: "GET", // "POST" recommended for production use
capabilities: printCapabilities, // provide url instead for lazy loading
customParams: {
mapTitle: "OSM Printing",
comment: "This demo shows how to use GeoExt.PrintMapPanel with OSM"
}
});
var map = new OpenLayers.Map();
map.addLayer(new OpenLayers.Layer.OSM());
var lonLat = new OpenLayers.LonLat( userLon ,userLat ).transform(
new
OpenLayers.Projection("EPSG:4326"), //
transform from WGS 1984
map.getProjectionObject() // to
Spherical Mercator Projection
);
var zoom=10;
var markers = new
OpenLayers.Layer.Markers( "Markers" );
map.addLayer(markers);
markers.addMarker(new
OpenLayers.Marker(lonLat));
map.setCenter (lonLat, zoom);
// A MapPanel with a "Print..." button
mapPanel = new GeoExt.MapPanel({
renderTo: "content",
width: 1000,
height: 800,
map: map,
zoom: 10,
bbar: [{
text: "Print...",
handler: function(){
// A window with the PrintMapPanel, which we can use to adjust
// the print extent before creating the pdf.
printDialog = new Ext.Window({
title: "Print Preview",
width: 500,
autoHeight: true,
items: [{
sourceMap: mapPanel,
printProvider: printProvider,
xtype: "gx_printmappanel",
// use only a PanPanel control
map: {controls: [new OpenLayers.Control.PanPanel()]}
}],
bbar: [{
text: "Create PDF",
handler: function(){ printDialog.items.get(0).print(); }
}]
});
printDialog.show();
}
}]
});
I have tried using without ext.js but was not able to get how to pass the
map div as parameter,so i used the geoext but that was giving the above
exception.
My config File:
hosts:
- !localMatch
dummy: true
- !ipMatch
ip: http://localhost:8000/print-servlet-1.1/
- !dnsMatch
host: localhost
port: 8000
- !dnsMatch
host: demo.mapfish.org
port: 8000
layouts:
mainPage:
rotation: true
pageSize: A4
header:
height: 50
items:
- !text
font: Helvetica
fontSize: 30
align: right
text: '${mapTitle}'
items:
- !map
spacingAfter: 30
width: 440
height: 483
- !text
text: '${comment}'
spacingAfter: 30
footer:
height: 30
items:
- !columns
items:
- !text
backgroundColor: #FF0000
align: left
text: Copyright Juventus Techonologies
- !text
align: right
text: 'Page ${pageNum}'
anybody help me out with please..