Thursday, April 19, 2012

Uploading an image which is within <img> tag to server

Can I upload an image to my web server. I know that, If I have file input in my web page, then I can easily upload it and get it like $_FILE["name"] at my server(PHP). But I am developing a web page for iPad which doesn't expose the file system. But later, this will be handled by using phone gap. But now for the demo sake, I want to show that upload works. So, now assume that I have the path to a file. And I have it in my web page like <img src="path" alt="">

Can I upload this to my server by any means?

Filling form with Datamapper ORM object - Codeigniter

I'm trying to get a form populated by data coming from a Datamapper object.

Here's my controller code:

function find()
$sub_list = new Subject();
$data['s'] = $sub_list->all;

$this->load->view('professors/find', $data);


In my view I'd want to show a dropdown form with the data coming from that object but I can't make it work.
This code:

<?php echo form_dropdown('accesso', $s);?>

Just show me "Subject" for every field in the db.

Many thanks for the help! I'm sorry for the silly issue!

EDIT: Problem solved!

<?php foreach ($s as $a):?>
<?php $options[$a->name] = $a->name; ?>
<?php endforeach ?>
<?php echo form_dropdown('accesso', $options);?>


wxPython TextCtrl auto detect file/folder path [closed]

Is there a mechanism that detects (highlight and generate mouse event) a file or a folder path in a wx.TextCtrl?
A similar mechanism exists for URL detection (using style = wx.TE_AUTO_URL with wx.TE_RICH).


"This is an example how I want TextCtrl to detect C:\Temp\Folder\temp.txt as a path."


Set Content/Media type - Restlet

How do you set the content type in Restlet (version 2.0 for google app engine)? In this case, I'd like to set the content type to ""text/xml".

I have:

public class SubResource  extends ServerResource {

public Representation get(Representation representation){

StringRepresentation sr = new StringRepresentation(getSomeXml());

return sr;

I'm unsure even if it is a value that is set in the Representation, or if it is set from the ServerResource class the same way that the return code is.


    StringRepresentation sr = new StringRepresentation(getSomeXml());

Unattached git repository?

I have a folder running locally that contains a website. It runs on xampp on my computer quite happily. I know that has been hooked up to git in the past and I continue to add, commit and push my changes through the command line and it all works as all my other git repos do, except they update on my github dashboard online to show when they were last edited etc.

Problem is this one folder, Demo, isn't updating the supposedly connected repo on my github dashboard.. I've made loads of changes and I'm committing it to somehwere but it's not where I expected... its showing the most recent changes being over 4 months ago! Is there any way to easily reconnect the two? I dont' mind losing whatevers in the ghost repo showing on github but I can't lose anything on my local Demo folder. I'm happy enough on git to do the basics but if anything unexpected happens I get terrified I'm going to delete everything!

SQL Datetime Not Equal To Is Not Working

I have a database consisting of a Customer, Product, and Transaction table.

I'm trying to write an SQL statement to list all customers' names and SSN's for those customers who have made no transaction in the year 2000.

The TransactionDate column in the Transaction table is a Date/Time data type (e.g. 2000-12-18 00:00:00).

This is the SQL code I've written:

SELECT DISTINCT CustomerName, Customer.CustomerSSN 
FROM Customer, Transaction
WHERE Customer.CustomerSSN=Transaction.CustomerSSN
AND YEAR(TransactionDate)<>2000;

The not equal to symbol (<>) seems to not be working for some reason. When I change it to an equal sign, it does return the correct result...

Any advice is appreciated.

Connection refused on bluetooth socket.connect() - android

First, I know this issue has been up before but none of the sugested solutions i found solves my problem...

After pairing device with

Method m = device.getClass().getMethod("createRfcommSocket", new Class[] {int.class});
tmp = (BluetoothSocket) m.invoke(device, 1);

I try to connect using

boolean connected = false;
String cause = "";
for(int i=0; i<3; i++){
try {
} catch (IOException e) {
Log.e("btact","fail"+i+" - "+e.getMessage());
cause = e.getMessage();
connected = true;

try {
} catch (IOException e2) {
Log.e(TAG, "unable to close() " + mSocketType +
" socket during connection failure", e2);

Log.e("----btact----", cause);

This gives me
fail0 - Connection refused
fail1 - File descriptor in bad state
fail2 - File descriptor in bad state
File descriptor in bad state

Whay may cause this problem and how do I solve it?

How can I check if the given URL of an image exists using GWT?

I want to check if a given URL exists and it's an image, in order to create a new Image(String url) from it. If the given URL is not an image then it should return an error.

CSV to PLIST conversion Issue

I am trying to convert a csv file into plist but I am quiet unsuccessful in doing that.
my csv file looks like:

pro1 |
add 1| add 2
bb 4
cc 5
pro2 |
add 1| add 2
ee 5
cc 8
qq 10
ww 9
ee 4
tt 7
pro3 |
add 1| add 2
gg 2
hh 1
qq 11
oo 19

I am thinking of how to make a separate array for every pro?

SQL query doesn't return full results for only one field

I'm having a problem using VBA to execute a SQL query and copy the results into an Excel worksheet.

When the sub excecutes, it only copies rows that are multiples of 256 (so rows 256, 512, 768 etc are the only ones that are filled into Excel). I'm having no problem copying any of the other fields from the database. Also, when I run the same query in MySQL it works fine. Being fairly new to both SQL and VBA I can't see any reason why this particular field should be causing trouble. The only thing I can think of is that its contents are a string that always begins with an underscore (and I only mention that because it's the only difference between it and some of the other fields).

Does anybody have any ideas as to why this may be happening?



Mysql double sort

I would like to double sort my user list. Is this possible within one mysql query?

  1. sort by activity

  2. sort by ID

for example:

1 Jack Active 
2 Jill Active
5 Jens Active
3 Harry Inactive
4 Larry Inactive
6 Luke Inactive

how to implement security on sharepoint 2010 web services .net

We do have a Fast Search server running within our servers. We would like to use web services to pull data from FAST search server. Here is the code block I have:

 SearchProxy.QueryService queryService = new SearchProxy.QueryService();
// Use the credentials of the user running the client application:
queryService.Credentials = System.Net.CredentialCache.DefaultCredentials;

// Run the QueryEx method, returning the results to a DataSet:
System.Data.DataSet queryResults = queryService.QueryEx(GetXMLString());

It is working fine in my local machine but when deploying it to the web server. It fails. The DefaultCredenticals will get my real identity in my local but in web server, it doesn't know who the user is.

It works when we provide the domain and username manually with the following syntax:

queryService.Credentials = new System.Net.NetworkCredential("username", "p@ssw0rd", "domainName");

Is there a method to obtain the user identity automatically When using get into the site via a browser?

Thanks much for your guidance...

text_widget.insert(1.0, "\\") will only display one slash

The title says all. I have the following code, lines 9 and 18 contain said characters. Is there a way without using chr(92)?

def Conversion(self):
for i in range(len(self.t)):
if self.t[i]==chr(9):
elif self.t[i]==chr(10):
self.c="\begin{tabular} ["
self.c+="] \n"
for i in range(len(self.t)):
#self.c+=" "
if self.t[i]==chr(9):
elif self.t[i]==chr(10):

Also my .Write method looks like this:

class Output:
def __init__(self,master,x):
self.v.insert(1.0,"LaTeX code")
def Write (self,input):
if self.v.get(1.0,END)=="":

Grails : forward instead of redirect and fragment

i use forward instead of redirect (to hide parameters in the url), the problem is that i want to pass a fragment to forward, so my page will scroll to the specified location.
with redirect, this works :

redirect(controller: "mycontroller", action: "myaction", fragment: "anchor")

but with forward, it doesn't scroll to the anchor location :

forward(controller: "mycontroller", action: "myaction", fragment: "anchor")

any idea how to solve this ??

iOS5 combine CGAffineTransform with animationImages?

I'm pretty new to iOS animation and I'm wondering if it's possible to combine an transition between two images along with a translation animation of the UIImageView using CGAffineTransform?

In other words I have two images that I want to animate between, and then I want to apply a simultaneous translation so that the whole thing moves across the page while moving back and forth between the two images.

I know I can apply a CGAffineTransformConcat to combine two CGAffineTransforms such as a CGAffineTransformTranslate and something else. But I don't see a CGAffineTransform which allows me to transition to another UIImage.

The only way I know to animate between images is to use the UIImageView animationImages array combined with startAnimating. However, I don't know how to combine this with a translation like so:

UIImageView* textView = [[UIImageView alloc] initWithFrame:bunnyImage.frame]; 

textView.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"bunnyclose.png"],
[UIImage imageNamed:@"bunnytalk.png"],

textView.animationDuration = 1.0;
textView.animationRepeatCount = 8;
[textView startAnimating];

[self.view addSubview:textView];

Any suggestions?

How do you get entity's schema name using Code First (Entity Framework) and DbContext?

Our database was designed in such a way where there are various schemas for production and various equivalent schemas for test. For example, many tables rest in MyProduction schema while the same tables live in MyTest schema.

What I want to do is determine which schema a table is using so I know which one to change it to. So, by default, everything will be under the production schemas. In the OnModelCreating event of the DbContext, if I need to point to test (determined by some true/false configuration), I need to determine the production schema being used, then point it to it's test equivalent.

I'm already aware of how to set the schema but can't find how to get it. Any ideas how I can determine the schema that a table is using?

Thank You.

how to do to make sure phonegap js load just once time in an app with many separate pages?

Use phonegap 1.6,now called cordova 1.6, with jquery mobile 1.0.1,but I feel performance is a problem.
Also with some other js libs,such as iscroll.js, plus the performance problem.

Can I load phonegap js just once,and later all pages can still use phonegap api?

I have an idea that Page A load phonegap js ,and nested iframe refer Page B.
Page B will replace by other pages. Can Pages in iframe use its parent phonegap api?

eg: parent.(all phonegap api)

Customised batch processing of PSD files (Adobe Photoshop / Adobe InDesign)

I have some 200 Photoshop templates with me and I want to be able to add certain images and text to each template separately.The path to the image as well as the text is given in an excel file which again has 200 rows.So basically template1 should contain image and text from row1, template2 from row2 and so on. Could any one please direct me in the right direction?

Thanking you,

Rails, Mongoid, and Devise nested Models

I am trying to Nest a class within Devise that will hold a user's skills and desired skills into an array but I can not seem to get my form objects to save into the array.

    Class User
include Mongoid::Document
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable

## Database authenticatable
field :email, :type => String, :null => false, :default => ""
field :encrypted_password, :type => String, :null => false, :default => ""

## Recoverable
field :reset_password_token, :type => String
field :reset_password_sent_at, :type => Time

## Rememberable
field :remember_created_at, :type => Time

## Trackable
field :sign_in_count, :type => Integer, :default => 0
field :current_sign_in_at, :type => Time
field :last_sign_in_at, :type => Time
field :current_sign_in_ip, :type => String
field :last_sign_in_ip, :type => String

field :first_name
field :last_name

field :location

index([[:skills, :desired]], :background => true)

validates_presence_of :first_name, :last_name, :location
validates_uniqueness_of :first_name, :last_name, :email, :case_sensitive => false
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :remember_me, :location

embeds_one :skills
class Skills
include Mongoid::Document

field :skills, type => String
field :desired, type => String

embedded_in :user

How do I fix my model and view so a person can add multiple skills and desired skills as sign up? (I am a rails beginner)

Finding the difference between 2 dates and iterating an image based on the difference

Ive managed to loop through a table and get the difference in days between 2 dates adjacent to each other in the table.

Multiple entries have the same date, i have it now that when that date changes, it displays an image however i want it to display the image as many times as the difference in date

$sql = mysql_query("SELECT * FROM Films_Info") 
or die(mysql_error());

$last_value = null;

while ($row = mysql_fetch_assoc($sql)) {

if (!is_null($last_value)) {
$a = new DateTime($row['FilmRelease']);
echo "<p>".$row['FilmName']."</p>";
$interval = $a->diff(new DateTime($last_value));
//echo $interval->format('%d days');
$i = 0;

$howManydays = $interval->days;

for ( $i; $howManydays; $i++) {
echo "<img src=\"day.jpg\" />";
$howManydays = 0;


$last_value = $row['FilmRelease'];

Sorting Listbox Items VB

So I have two listboxes. Listbox1 gathers files from a directory and I have an add button to add selected files from Listbox1 over to Listbox2.

Is there a way to manually sort these items? Maybe with an up down buttons?

The reason I'd like to sort/reorder is I'll have a process that will run those selected files and each file will have to produce another file unqiue to the filename.

A quick example would be process FILE1.txt and produce FILE1.pdf, etc.

Is there an easier way to accomplish the sort/reorder?

CakePHP $this->Form->end('button text'); on same line with something

I have a simple cakephp form and would like for the 'save translation' button to be to the LEFT of a link which cancels and returns the user to the index, but I can't seem to get it working. It always puts the cancel link below the button.

Code I have now:

<?php echo $this->Form->end('Save Translation'); ?>
<?php echo $html->link('Cancel', array('action' => 'index')); ?>

Code I've tried:

echo $this->Form->end('Save Translation',array('label'=>'Save Translation','div' => false));

ASP.NET Localize

A simple question. I have a site with localization (with .resx files) and when i need to insert localized text i use a code like this:

<asp:Localize Text="<%$ Resources: MyResource, Default_BannerHomeTitle %>" runat="server">SOME_TEXT_HERE_OR_NOT?</asp:Localize>

The question is if anyone knows what's the utility of the text between the asp:Localize tag -> "SOME_TEXT_HERE_OR_NOT?"

The real value come from the .resx file and the text "SOME_TEXT_HERE_OR_NOT?" is obviusly deleted when the page is rendered.

Is this text used in some situation? or is never used?

thanks in advance!

Instead of Session variable where i can save my temp data in mvc?

I have created a mvc3 application.
Currently saving submit form value into Session as i need to do some stuff on that before
save changes to database.

Is there any other good way to store temp data in mvc like ViewState?

Error when I try to create an .accdb file in C#

This is my code that creates an .accdb file if it can't find one :

Catalog cat = new CatalogClass();
string createStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=|DataDirectory|/saveDB.accdb;";
Table tbl = new Table();
tbl.Name = "saveDB";
tbl.Columns.Append("ID", DataTypeEnum.adGUID);
tbl.Columns.Append("Tensiune", DataTypeEnum.adDouble);
tbl.Columns.Append("Frecventa", DataTypeEnum.adDouble);
tbl.Columns.Append("Rezistenta", DataTypeEnum.adDouble);
tbl.Columns.Append("Inductanta", DataTypeEnum.adDouble);
tbl.Columns.Append("Capacitate", DataTypeEnum.adDouble);
tbl.Columns.Append("Elemente", DataTypeEnum.adVarWChar, 25);
tbl.Columns.Append("Tip", DataTypeEnum.adVarWChar, 25);

But when I run it in the program i get this runtime error :

System.Runtime.InteropServices.COMException (0x80004005): Not a valid file name.
at ADOX.CatalogClass.Create(String ConnectString)

I can't figure what's the problem with the file name, so if anyone has any idea, please help.

Java speed access array index versus temp variable

What is faster in Java. Accessing an array index directly multiple times, or saving the value of the array index to a new variable and use this for following compution?

acces index

if ((shape.vertices[0].x >= fromX && shape.vertices[0].x <= toX) || // left side of shape in screen
(shape.vertices[0].x <= fromX && shape.vertices[0].x + shape.width >= fromX) || // right side of shape in screen
(shape.vertices[0].x >= fromX && shape.vertices[0].x + shape.width <= toX)) { // shape fully in screen

// ...

temp variable

float x = shape.vertices[0].x;
float y = shape.vertices[0].y;
if ((x >= fromX && x <= toX) || // left side of shape in screen
(x <= fromX && x + shape.width >= fromX) || // right side of shape in screen
(x >= fromX && x + shape.width <= toX)) { // shape fully in screen

// ...

Make asset pipeline act like production on development

I am experiencing some problems with assets on production: missing ones, stuff compiled into the wrong files (javascript for "/admin" getting compiled into the frontend code and so on). Most of the assets come from engines. I want to debug and optimize this.

For that, I need to precompile, serve and fail on my development environment just like it is done on production.

I have added some lines to my config/development.rb:

  config.serve_static_assets = true
config.assets.precompile += %w( store/all.js store/all.css admin/all.js admin/all.css ) # @TODO: clean up, and optimize.
config.assets.compile = false

Running this with rake RAILS_GROUPS=assets RAILS_ENV=development assets:precompile gives me all the assets and the manifest.yml in public/.

But then the server fails:

Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError in Spree/home#index

Showing /xxxx/app/views/spree/shared/_head.html.erb where line #13 raised:

favicon.ico isn't precompiled

favicon.ico isn't precompiled. But it is! Its there, in the public dir, in manifest.yml, and I can fetch it with the browser (or wget): http://localhost:3000/assets/favicon.ico.

NOTE Favicon is simply the first asset called. If I strip out favicon, the problem simply surfaces with the next asset, being "all.js", or, when that is stripped, "all.css", and so on. I can strip it untill "footer_bg.png", and it will then fail there. Again: the problem is not favicon, but the fact that the development environment does not see the precompiled assets at all.

What more is needed to get development asset pipeline similar to production?

EDIT: More explicit explanation that favicon is not the problem, merely a symptom.

serach product with their specifications filter

I have a table that contain products with their specifications.i created a sample of data in!2/15575/1 .I want create search form that users can search products by their specifications.for example user search laptop with RAM=2 and VGA=512 or VGA=1.
I wrote a query,but not working.please help me.
this example:
result: 1525,1535,k5,k6
enter image description here

Skip the cell and the content of a DataTemplateColumn in a DataGrid

I am trying to tab through a datagrid, but at the end of the row I have a template column that is taking in a tab. I have set the datagrid cell style to not focusable and istabstop = false, but it still seems to be going into the content. Is there a property for a TemplateColumn that will have it be skipped by tabbing completely?


How to exclude one table from drop-and-create-tables with Ecliselink?

I use Eclipselink 2.3.2 and want to know, if there is an way to exclude a single table/entity to be excluded from ddl-generation strategy drop-and-create-tables? I need to preserve the content of this table, while all other tables should be droped and been created complete new.

The reason is that the domain model is under heavy development so there are changed all and everywhere. But one single table (containing postal codes) should be preserved, because they are needed for development, and it takes to long to insert them all at every server start.

I know one way is to use two different persistence units. But this would cause some other trouble, so this not my preferred way.

Summary: Does anybody know a way to exclude a single table from droping while all other tables get droped and been recreated at each server start with ecliselink 2.3.2 (and Glassfish 3.1.2 )?