instruction stringlengths 0 30k ⌀ |
|---|
Accessing html parameter in PHP |
|php| |
I'm trying to do a simple test php script for sessions. Basically it increments a counter (stored in $_SESSION) every time you refresh that page. That works, but I'm trying to have a link to destroy the session which reloads the page with the ?destroy=1 parameter. I've tried a couple of if statements to see if that parameter is set and if so to destroy the session but it doesn't seem to work.
I've even put an if statement in the main body to popup a message if the parameter is set - but it doesn't seem to be picked up.
I know I'm doing something silly (I'm a php newbie) but I can't seem to find what it is...
See code here:
<?php
if ($_POST['destroy'])
{
session_destroy();
}
else
{
session_start();
}
?>
<html>
<head>
<title>Session test</title>
</head>
<body>
<?php
if (isset($_POST['destroy']))
{
echo "Destroy set";
}
$_SESSION['counter']++;
echo "You have visited this page " . $_SESSION['counter'] . " times" . "<BR>";
echo "I am tracking you using the session id " . session_id() . "<BR>";
echo "Click <a href=\"" . $_SERVER['PHP_SELF'] . "?destroy=1\">here</a> to destroy the session.";
?> |
@ Burton: I think he meant the other way, at least from the example on the linked page:
Chronic.parse('tomorrow')
#=> Mon Aug 28 12:00:00 PDT 2006
Chronic.parse('monday', :context => :past)
#=> Mon Aug 21 12:00:00 PDT 2006
Chronic.parse('this tuesday 5:00')
#=> Tue Aug 29 17:00:00 PDT 2006
I thought I would take a stab at it too until I realized! (nice implementation though) |
[Dependency Walker][1] is super useful for finding out which dll is missing from the installer. Once you know the dll, you can find what merge module it is in using the [Merge Module Finder][2].
[1]: http://www.dependencywalker.com/
[2]: http://www.installsite.org/pages/en/msi/msm.htm |
What is the "best" simple instal system for XP/Vista? |
|windows|installation| |
Heavy emphasis on simple. I've never made an installer and I'd rather not have to learn much. A system that I could hand a pile of files to and it would make some smart guesses about where to put them would be ideal.
Go ahead and answer the general question.
However In my cases I'm stuck with some extra constraints. The program to be installed is written in VB6 (or is it 5?) and a few previous versions of VB, so it's *not* going to be updated any time soon. I have a running install and will have a Clean VM to play with So I'll be doing a loop of: run the install, find where it's broken, fix it, add that to the installer, revert the VM, try again. If anyone has a better approach I'm open to suggestions.
I *MUST* get it working on XP and I'd really like to also have something that will work on Vista as well. |
What is the "best" simple install system for XP/Vista? |
How I hide empty Velocity variable names ? |
|java|templates|struts|velocity| |
I am using Struts + Velocity in a Java application, but after I submit a form, the confirmation page (Velocity template) shows the variable names instead an empty label, like the Age in following example:
> **Name**: Fernando
> **Age**: {person.age}
> **Sex**: Male
I would like to know how to hide it! |
Eric Z Beard:
> the activity date is meant to indicate the local time zone, but not a specific one
Okay - back to the drawing board. Try this:
where t.TheDateINeedToCheck BETWEEN (
dateadd(hh, (tz.Offset + ISNULL(ds.LocalTimeZone, 0)) * -1, @ActivityDate)
AND
dateadd(hh, (tz.Offset + ISNULL(ds.LocalTimeZone, 0)) * -1, (@ActivityDate + 1))
)
which will translate the @ActivityDate to local time, and compare against that. That's your best chance for using an index, though I'm not sure it'll work - you should try it and check the query plan.
The next option would be an indexed view, with an indexed, computed TimeINeedToCheck *in local time*. Then you just go back to:
where v.TheLocalDateINeedToCheck BETWEEN @ActivityDate AND (@ActivityDate + 1)
which would definitely use the index - though you have a slight overhead on INSERT and UPDATE then.
|
[InnoSetup][1] or [NSIS][2], whichever seems easier to you. [ISTool][3] is a nice GUI tool for InnoSetup which makes creating setup scripts even easier.
[1]: http://www.jrsoftware.org/
[2]: http://nsis.sourceforge.net/
[3]: http://www.istool.org |
As long as a MySQL dump file doesn't exceed the [SQLite](http://www.sqlite.org/lang.html) query language, you should be able to migrate fairly easily:
tgl@moto~$ mysqldump old-database > old-database-dump.sql
tgl@moto~$ sqlite3 -init old-database-dump.sql new-database
I haven't tried this myself... |
As long as a MySQL dump file doesn't exceed the [SQLite](http://www.sqlite.org/lang.html) query language, you should be able to migrate fairly easily:
tgl@moto~$ mysqldump old-database > old-database-dump.sql
tgl@moto~$ sqlite3 -init old-database-dump.sql new-database
I haven't tried this myself.
_UPDATE:_
Looks like you'll need to do a couple edits of the MySQL dump. I'd use sed, or [Google for it.](http://www.perlmonks.org/index.pl?node_id=150476)
Just the comment syntax, auto_increment & TYPE= declaration, and escape characters differ. |
I thin the only real problem is that it makes the XML harder to read. e.g.
<Something>
<Contains>
<An>
<Address>15 Sample St
Example Bay
Some Country</Address>
</An>
</Contains>
</Something>
If pretty XML isn't a concern, I'd probably not worry about it, so long as it's working. If pretty XML is a concern, I'd convert the explicit newlines into `<br />` tags or `\n` before embedding them in the XML. |
I think the only real problem is that it makes the XML harder to read. e.g.
<Something>
<Contains>
<An>
<Address>15 Sample St
Example Bay
Some Country</Address>
</An>
</Contains>
</Something>
If pretty XML isn't a concern, I'd probably not worry about it, so long as it's working. If pretty XML is a concern, I'd convert the explicit newlines into `<br />` tags or `\n` before embedding them in the XML. |
First of all, [here's a great article with tips on unit testing][1]. Secondly, I found a great way to avoid making tons of changes in old code is to just refactor it a little until you can test it. One easy way to do this is to make private members protected, and then override the protected field.
For example, let's say you have a class that loads some stuff from the database during the constructor. In this case, you can't just override a protected method, but you can extract the DB logic to a protected field and then override it in the test.
public class MyClass {
public MyClass() {
// undesirable DB logic
}
}
becomes
public class MyClass {
public MyClass() {
loadFromDB();
}
protected void loadFromDB() {
// undesirable DB logic
}
}
and then your test looks something like this:
public class MyClassTest {
public void testSomething() {
MyClass myClass = new MyClassWrapper();
// test it
}
private static class MyClassWrapper extends MyClass {
@Override
protected void loadFromDB() {
// some mock logic
}
}
}
This is somewhat of a bad example, because you could use DBUnit in this case, but I actually did this in a similar case recently because I wanted to test some functionality totally unrelated to the data being loaded, so it was very effective. I've also found such exposing of members to be useful in other similar cases where I need to get rid of some dependency that has been in a class for a long time.
I would recommend against this solution if you are writing a framework though, unless you really don't mind exposing the members to users of your framework.
It's a bit of a hack, but I've found it quite useful.
[1]: http://devver.net/blog/2008/07/tips-for-unit-testing/ |
Large File Download |
|java|browser|flash|silverlight| |
Internet Explorer has a file download limit of 4GB (2 GB on IE6)
(More info here: [http://support.microsoft.com/kb/298618][1])
I am working on a site that will allow the user to download very large files (up to and exceeding 100GB)
What is the best way to do this ***without using FTP***. I don't think Flash or Silverlight can save files to the client so as far as I know they won't cut it.
I'm guessing we will need an ActiveX or Java applet to pull this off. Something like the download manager that MSDN uses.
Does anyone know of a commercial (or free) component that will do that? We do not want the user to have to install a "browser wide" download manager (like GetRight), we want it to only work with downloading on our site.
[1]: http://support.microsoft.com/kb/298618 |
|java|flash|browser|silverlight| |
Internet Explorer has a file download limit of 4GB (2 GB on IE6). Firefox does not have this problem (haven't tested safari yet)
(More info here: [http://support.microsoft.com/kb/298618][1])
I am working on a site that will allow the user to download very large files (up to and exceeding 100GB)
What is the best way to do this ***without using FTP***. The end user must be able to download the file from there browser using HTTP. I don't think Flash or Silverlight can save files to the client so as far as I know they won't cut it.
I'm guessing we will need an ActiveX or Java applet to pull this off. Something like the download manager that MSDN uses.
Does anyone know of a commercial (or free) component that will do that? We do not want the user to have to install a "browser wide" download manager (like GetRight), we want it to only work with downloading on our site.
[1]: http://support.microsoft.com/kb/298618 |
|java|flash|silverlight|browser| |
Internet Explorer has a file download limit of 4GB (2 GB on IE6). Firefox does not have this problem (haven't tested safari yet)
(More info here: [http://support.microsoft.com/kb/298618][1])
I am working on a site that will allow the user to download very large files (up to and exceeding 100GB)
What is the best way to do this ***without using FTP***. The end user must be able to download the file from there browser using HTTP. I don't think Flash or Silverlight can save files to the client so as far as I know they won't cut it.
I'm guessing we will need an ActiveX or Java applet to pull this off. Something like the download manager that MSDN uses.
Does anyone know of a commercial (or free) component that will do that? We do not want the user to have to install a "browser wide" download manager (like GetRight), we want it to only work with downloading on our site.
**Update:** Here is some additional info to help clarify what I'm trying to do. Most of the files above the 4GB limit would be large HD video files (its for a video editing company). These will be downloaded by users across the internet, this isn't going to be people on a local network. We want the files to be available via HTTP (some users are going to be behind firewalls that aren't going to allow FTP, Bittorrent, etc.). The will be a library of files the end user could download, so we aren't talking about a one time large download. The will be download different large files on a semi-regular basis.
So far Vault that @Edmund-Tay suggested is the closest solution so far. The only problem is that it doesn't work for files larger than 4GB (it instantly fails before starting the download, they are probably using a 32bit integer somewhere that the content length of the file exceeds).
A java applet (or ActiveX component since the problem only exist in IE) that worked like the article @spoulson linked to would be the best solution, but so far I haven't had any luck finding one that does anything like that (multipart downloads, resume, etc.).
It looks like we might have to write our own. Another option would be to write a .Net application (maybe ClickOnce) that is associated with an extension or mime type. Then the user would actually be downloading a small file from the web server that opens in the exe/ClickOnce app that tells the application what file to download. That is how the MSDN downloader works. The end user would then only have to download/install an EXE once. That would be better than downloading an exe every time they wanted to download a large file.
[1]: http://support.microsoft.com/kb/298618 |
Yup, SVN for preference unless you really need git's particular features. SVN is hard enough; It sounds like git is more complicated to live with. You can get hosted svn from people like [Beanstalk](http://www.beanstalkapp.com/) - unless you have in-house Linux people, I'd really recommend it. Things can go wrong horribly easily and it's nice to have someone else whose job it is to fix it.
There's an excellent [tutorial](http://www.ericsink.com/scm/source_control.html) on revision control from Eric Sink which is worth reading no matter which system you use. |
Try this:
CREATE function [SplitWordList]
(
@list varchar(8000)
)
returns @t table
(
Word varchar(50) not null,
Position int identity(1,1) not null
)
as begin
declare
@pos int,
@lpos int,
@item varchar(100),
@ignore varchar(100),
@dl int,
@a1 int,
@a2 int,
@z1 int,
@z2 int,
@n1 int,
@n2 int,
@c varchar(1),
@a smallint
select
@a1 = ascii('a'),
@a2 = ascii('A'),
@z1 = ascii('z'),
@z2 = ascii('Z'),
@n1 = ascii('0'),
@n2 = ascii('9')
set @ignore = '''"'
set @pos = 1
set @dl = datalength(@list)
set @lpos = 1
set @item = ''
while (@pos <= @dl) begin
set @c = substring(@list, @pos, 1)
if (@ignore not like '%' + @c + '%') begin
set @a = ascii(@c)
if ((@a >= @a1) and (@a <= @z1))
or ((@a >= @a2) and (@a <= @z2))
or ((@a >= @n1) and (@a <= @n2))
begin
set @item = @item + @c
end else if (@item > '') begin
insert into @t values (@item)
set @item = ''
end
end
set @pos = @pos + 1
end
if (@item > '') begin
insert into @t values (@item)
end
return
end
Test it like this:
select * from SplitWordList('Hello John Smith') |
I don't believe SQL Server has a built-in split function, so other than a UDF, the only other answer I know is to hijack the PARSENAME function:
SELECT PARSENAME(REPLACE('Hello John Smith', ' ', '.'), 2)
PARSENAME takes a string and splits it on the period character. It takes a number as it's second argument, and that number specifies which segment of the string to return (working from back to front).
SELECT PARSENAME(REPLACE('Hello John Smith', ' ', '.'), 3) --return Hello
Obvious problem is when the string already contains a period. I still think using a UDF is the best way...any other suggestions? |
Which language are using? It seems like pretty much all of them have built-in SQL escape functions that would be better to use.
For example, PHP has [mysql_real_escape_string](http://us2.php.net/manual/en/function.mysql-real-escape-string.php) and [addslashes](http://us2.php.net/manual/en/function.addslashes.php). |
I would also escape comments (double dash)
-- |
You're better off using prepared statements with placeholders. Are you using PHP, .NET...either way, prepared statements will provide more security, but I could provide a sample. |
I've looked at WorldPay and SecPay in the past; you need to know your onions to use them competently, I think - if you want really nice integration, at any rate. |
No, unfortunately, and if you think about it, that information would be worthless anyway since the file could become locked the very next second (read: short timespan).
Why specifically do you need to know if the file is locked anyway? Knowing that might give us some other way of giving you good advice. |
Rockbox audio format |
|c|audio|rockbox| |
How do you specify a callback for rb->pcm_play_data()? |
I was just listening to a Podcast from Scott Hanselman this morning, where he talks about internationalization, especially the really tricky things, like Turkish (with it's four i's) and Thai:
[http://www.hanselminutes.com/default.aspx?showID=135][1]
Also, Jeff Atwood had a post:
[http://www.codinghorror.com/blog/archives/001075.html][2]
[1]: http://www.hanselminutes.com/default.aspx?showID=135
[2]: http://www.codinghorror.com/blog/archives/001075.html |
The problem with a generic tool is that it is very difficult to come up with a set of rules that will only match against a genuine attack.
SQL keywords are all English words and don't forget that the string
DROP TABLE users;
is perfectly valid in a form field that, for example, contains an answer to a programming question.
The only sensible option is to sanitise the input before ever passing it to your database but pass it on nonetheless. Otherwise lots of perfectly normal, non-malicious users are going to get banned from your site. |
You might be able to get some implementation ideas from the [Ruby/ProgressBar library][1], which generates text progress bars. I stumbled across it a couple of months back but haven't made any use of it.
[1]: http://0xcc.net/ruby-progressbar/ "Ruby/ProgressBar" |
Not sure if that helps (i found the ccnet Documentation somewhat unhelpful at times):
[Using CruiseControl.NET with MSTest][1]
[1]: http://confluence.public.thoughtworks.org/display/CCNET/Using+CruiseControl.NET+with+MSTest |
In my opinion it is more a question of personal preference. nAnt is a great framework and MSBuild is almost as capable. With the ability to easily develop custom tasks (in both frameworks) you can accomplish almost anything that you need to do.
I cannot answer the "still supported" portion of your questions, but I would say if you are already comfortable with nAnt then it's probably viable. If you (or someone in your group) is familiar with MSBuild then that is a fine way to go as well. |
The easiest *distance* would of course be to just consider the colors as 3d vectors originating from the same origin, and taking the distance between their end points.
If you need to consider such factors that green is more prominent in judging intensity, you can weigh the values.
[ImageMagic](http://www.imagemagick.org/Usage/color/#grayscale) provides the following scales:
* red: 0.3
* green: 0.6
* blue: 0.1
Of course, values like this would only be meaningful in relation to other values for other colors, not as something that would be meaningful to humans, so all you could use the values for would be similiarity ordering. |
Well, since you can not have one part OSGi and one part non-OSGi you'll need to make your entire app OSGi. In its simplest form you make a single OSGi bundle out of your entire application. Clearly this is not a best practice but it can be useful to get a feel for deploying a bundle in an OSGi container (Equinox, Felix, Knoplerfish, etc).
To take it to the next level you'll want to start splitting your app into components, components should typically have a set of responsibilities that can be isolated from the rest of your application through a set of interfaces and class dependencies. Identifying these purely by hand can range from rather straightforward for a well designed highly cohesive but loosely coupled application to a nightmare for interlocked source code that you are not familiar with.
Some help can come from tools like [JDepend][1] which can show you the coupling of Java packages against other packages/classes in your system. A package with low efferent coupling should be easier to extract into an OSGi bundle than one with high efferent coupling. Even more architectural insight can be had with pro tools like [Structure 101][2].
Purely on a technical level, working daily with an application that consists of 160 OSGi bundles and using Spring DM I can confirm that the transition from "normal" Spring to Spring DM is largely pain free. The extra namespace and the fact that you can (and should) isolate your OSGi specific Spring configuration in separate files makes it even easier to have both with and without OSGi deployment scenarios.
OSGi is a deep and wide component model, documentation I recommend:
- [OSGi R4 Specification][3]: Get the PDFs of the Core and Compendium specification, they are canonical, authoritative and very readable. Have a shortcut to them handy at all times, you will consult them.
- Read up on OSGi best practices, there is a large set of things you **can** do but a somewhat smaller set of things you **should** do and there are some things you should **never do** (DynamicImport: * for example).
Some links:
- [OSGi best practices and using Apache Felix][4]
- [Peter Kriens and BJ Hargrave in a Sun presentation on OSGi best practices][5]
- one key OSGi concept are Services, learn why and how they supplant the Listener pattern with the [Whiteboard pattern][6]
- [The Spring DM Google Group][7] is very responsive and friendly in my experience
[1]: http://clarkware.com/software/JDepend.html
[2]: http://www.headwaysoftware.com/products/structure101/index.php
[3]: http://www.osgi.org/Release4/Download
[4]: http://cwiki.apache.org/FELIX/presentations.data/best-practices-apachecon-20060628.pdf
[5]: http://developers.sun.com/learning/javaoneonline/2007/pdf/TS-1419.pdf
[6]: http://www.osgi.org/wiki/uploads/Links/whiteboard.pdf
[7]: http://groups.google.com/group/spring-osgi |
I think you put
$_POST['destroy']
Instead of
$_GET['destroy']
You need to use a form if you'd like to use a $\_POST variable. $\_GET variables are stored in the URL. |
After the advice here, I have devised the following function in VB which creates passable, although not always perfect (if a company name and a suite line are given, it combines the suite and city) usable data. Please feel free to comment/refactor/yell at me for breaking one of my own rules, etc.:
Public Function parseAddress(ByVal input As String) As Collection
input = input.Replace(",", "")
input = input.Replace(" ", " ")
Dim splitString() As String = Split(input)
Dim streetMarker() As String = New String() {"street", "st", "st.", "avenue", "ave", "ave.", "blvd", "blvd.", "highway", "hwy", "hwy.", "box", "road", "rd", "rd.", "lane", "ln", "ln.", "circle", "circ", "circ.", "court", "ct", "ct."}
Dim address1 As String
Dim address2 As String = ""
Dim city As String
Dim state As String
Dim zip As String
Dim streetMarkerIndex As Integer
zip = splitString(splitString.Length - 1).ToString()
state = splitString(splitString.Length - 2).ToString()
streetMarkerIndex = getLastIndexOf(splitString, streetMarker) + 1
Dim sb As New StringBuilder
For counter As Integer = streetMarkerIndex To splitString.Length - 3
sb.Append(splitString(counter) + " ")
Next counter
city = RTrim(sb.ToString())
Dim addressIndex As Integer = 0
For counter As Integer = 0 To streetMarkerIndex
If IsNumeric(splitString(counter)) _
Or splitString(counter).ToString.ToLower = "po" _
Or splitString(counter).ToString().ToLower().Replace(".", "") = "po" Then
addressIndex = counter
Exit For
End If
Next counter
sb = New StringBuilder
For counter As Integer = addressIndex To streetMarkerIndex - 1
sb.Append(splitString(counter) + " ")
Next counter
address1 = RTrim(sb.ToString())
sb = New StringBuilder
If addressIndex = 0 Then
If splitString(splitString.Length - 2).ToString() <> splitString(streetMarkerIndex + 1) Then
For counter As Integer = streetMarkerIndex To splitString.Length - 2
sb.Append(splitString(counter) + " ")
Next counter
End If
Else
For counter As Integer = 0 To addressIndex - 1
sb.Append(splitString(counter) + " ")
Next counter
End If
address2 = RTrim(sb.ToString())
Dim output As New Collection
output.Add(address1, "Address1")
output.Add(address2, "Address2")
output.Add(city, "City")
output.Add(state, "State")
output.Add(zip, "Zip")
Return output
End Function
Private Function getLastIndexOf(ByVal sArray As String(), ByVal checkArray As String()) As Integer
Dim sourceIndex As Integer = 0
Dim outputIndex As Integer = 0
For Each item As String In checkArray
For Each source As String In sArray
If source.ToLower = item.ToLower Then
outputIndex = sourceIndex
If item.ToLower = "box" Then
outputIndex = outputIndex + 1
End If
End If
sourceIndex = sourceIndex + 1
Next
sourceIndex = 0
Next
Return outputIndex
End Function
Passing the parseAddress function "A. P. Croll & Son 2299 Lewes-Georgetown Hwy, Georgetown, DE 19947" returns:
2299 Lewes-Georgetown Hwy
A. P. Croll & Son
Georgetown
DE
19947
|
I've had to do similar things a few times. The easiest approach for me has been to write a script that pulls from one data source and produces an output for the new data source. Just do a `SELECT *` query for each table in your current database, and then dump all the rows into an `INSERT INTO` query for your new database. You can either dump this into a file or pipe it straight into the database frontend.
It's not pretty, but honestly, pretty hardly seems to be a major concern for things like this. This technique is quick to write, and it works. Those are my primary criteria for things like this.
You might want to check out [this thread](http://www.perlmonks.org/index.pl?node_id=150476), too. It looks like a couple of people have already put together basically what you need. I didn't look that far into it, though, so no guarantees. |
Microsoft loosened it's constraint on the Testing Platform by including it in Visual Studio 2008 Professional and allowing for the tests to be run from the command line with Framework 3.5 installed. We did a crossover for a client recently and so far they have been able to run all the tests without the need for NUnit. |
What you really should be doing is converting your XML to a format that preserves white-space.
So rather than seek to replace \n with <br /> you should wrap the whole block in a <pre>
That way, your address is functionally preserved (whether you include line breaks or not) and the XSTL can choose whether to preserve white-space in the result. |
Silverlight is the answer and Moonlight will be the linux equivalent and available shortly. We have done some beta testing on moonlight and found it fairly stable at with most of the Silverlight work we do. |
The SharePoint team is currently working on MOSS extensions for VS 2008 which will allow this type of functionality. This was available in VS 2005 with MOSS extensions, but has to be run off Windows Server with a full MOSS installation and the correct permissions set. |
Here's what I would do:
- First time out... "we're going to do this project jointly. I'm going to write the tests and you're going to write the code. Pay attention to how I write the tests, coz that's how we do things around here and that's what I'll expect of you."
- Following that... "You're done? Great! First let's look at the tests that are driving your development. Oh, no tests? Let me know when that is done and we'll reschedule looking at your code. If you're needing help to formulate the tests let me know and I'll help you." |
In your algorithm using the list from 2 to the root of the integer, you can improve performance by only testing odd numbers after 2. That is, your list only needs to contain 2 and all odd numbers from 3 to the square root of the integer. This cuts the number of times you loop in half without introducing any more complexity. |
Here's the briefest explanation:
A Turing Complete system means a system in which a program can be written that will find an answer (although with no guarantees regarding runtime or memory).
So, if somebody says "my new thing is Turing Complete" that means in principle (although often not in practice) it could be used to solve any computation problem.
Sometime's it's a joke... a guy wrote a Turing Machine simulator in vi, so it's possible to say that vi is the only computational engine ever needed in the world. |
Using .Equals is also a lot easier to *read*. |
Direct connections. |
|ip|private-ips|p2p| |
From a [Joel's post on Copilot][1]:
> Direct Connect! We’ve always done
> everything we can to make sure that
> Fog Creek Copilot can connect in any
> networking situation, no matter what
> firewalls or NATs are in place. To
> make this happen, both parties make
> outbound connections to our server,
> which relays traffic on their behalf.
> Well, in many cases, this isn’t
> necessary. So version 2.0 does
> something rather clever: it sets up
> the initial connection through our
> servers, so you get connected right
> away with 100% reliability. But then
> once you’re all connected, it quietly,
> in the background, looks for a way to
> make a direct connection. If it can’t,
> no big deal: you just keep relaying
> through our server. If you can make a
> direct peer-to-peer connection, it
> silently shifts your data onto the
> direct connection. You won’t notice
> anything except, probably, much faster
> communication.
How do they change the server connection to a P2P connection?
[1]: http://www.joelonsoftware.com/items/2007/01/26.html |
Direct TCP/IP connections in P2P apps |
|ip|p2p|private-ips| |
What are the best keyboard macros for programming in windows? |
|keyboard|macros|performance| |
I like putting shortcuts of the form "g - google.lnk" in my start menu so google is two keystrokes away. Win, g.
My eight or so most frequent applications go there.
I also make links to my solution files I am always opening "x - Popular Project.lnk"
Are there any better ways to automate opening frequently used applications? |
What I usually do in these situations is to add a separate field called DisplayOrder or something similar. Everything defaults to, say, 1... You then sort by DisplayOrder and then the Name. If you want something higher or lower on the list, you can tweak the display order accordingly while keeping your normal IDs as-is.
-- Kevin Fairchild |
Iterate over subclasses of a given class in a given module |
|python|oop| |
In Python, given a module X and a class Y, how can I iterate or generate a list of all subclasses of Y that exist in module X? |
For shortcuts I use **Launchy**
For macros I use **AutoHotKey**
Others will suggest **SlickRun** for shortcuts also.
|
There are lots and lots of classic peak detection methods, any of which might work. You'll have to see what, in particular, bounds the quality of your data. Here are basic descriptions:
1. Between any two points in your data, (x(0),y(0)) and (x(n),y(n)), add up y(i+1)-y(i) for 0 <= i < n and call this T ("travel") and set R ("rise") to y(n)- y(0) + k for suitably small k. T/R > 1 indicates a peak. This works OK if large travel due to noise is small or if noise distributes symmetrically around a base curve shape. For your application, accept the earliest peak with a score above a given threshold, or analyze the curve of travel per rise values for more interesting properties.
2. Use matched filters to score similarity to a standard peak shape (essenitally, use a normalized dot-product against some shape to get a cosine-metric of similarity)
3. Deconvolve against a standard peak shape and check for high values (though I often find 2 to be less sensitive to noise for simple instrumentation output).
4. Smooth the data and check for triplets of equally space points where, if x0 < x1 < x2, y1 > 0.5*(y0+y2), or check Euclidean distances like this: D((x0,y0),(x1,y1)) + D((x1,y1),(x2,y2)) > D((x0,y0),(x2,y2)), which relies on the triagnle inequality. Using simple ratios will again provide you a scoring mechanism.
5. Fit a very simple 2-gaussian mixture model to your data (for example, Numerical Recipes has a nice ready-made chunk of code). Take the earlier peak. This will deal correctly with overlapping peaks.
6. Find the best match in the data to a simple gaussian, cauchy, poisson, or what-have-you curve. Evaluate this curve over a broad range and subtract it froma copy of the data after noting it's peak location. Repeat. Take the earliest peak whose model parameters (stddev probably, but some applications might care about kurtosis or other features) meet some criterion.
Best match might be determined by the kind of match scoring suggested in #2 above.
I've done what you're doing before: finding peaks in DNA sequence data, finding peaks in derivatives estimated from measured curves, and finding peaks in histograms.
I encourage you to attend carefully to proper baselining. Wiener filtering or other filtering or simple histogram analysis is often an easy way to baseline in the presence of noise.
Finally, if you're data are typically noisy and you're getting data off the card as unreferenced single-ended output (or even referenced, just not differential), and if you're averaging lots of observations into each data point, try sorting those observations and throwing away the first and last quartile and averaging what remains. There are a host of such outlier elimination tactics that can be really useful.
|
I am not sure if MySql supports parameterized queries, if so, you should make an effort to go this route. This will ensure the users input can't do anything malicious.
Otherwise some "bad" characters in addition to what you mentioned would be semicolon (;) and comments (-- and /* */). |
Here is a UDF which will do it. It will return a table of the delimited values, haven't tried all scenarios on it but your example works fine.
<pre><code>
CREATE FUNCTION SplitString
(
-- Add the parameters for the function here
@myString varchar(500),
@deliminator varchar(2)
)
RETURNS
@ReturnTable TABLE
(
-- Add the column definitions for the TABLE variable here
[id] [int] IDENTITY(1,1) NOT NULL,
[part] [varchar](50) NULL
)
AS
BEGIN
Declare @iSpaces int
Declare @part varchar(50)
--initialize spaces
Select @iSpaces = charindex(@deliminator,@myString,0)
While @iSpaces > 0
Begin
Select @part = substring(@myString,0,charindex(@deliminator,@myString,0))
Insert Into @ReturnTable(part)
Select @part
Select @myString = substring(@mystring,charindex(@deliminator,@myString,0)+ 1,len(@myString) - charindex(' ',@myString,0))
Select @iSpaces = charindex(@deliminator,@myString,0)
end
If len(@myString) > 0
Insert Into @ReturnTable
Select @myString
RETURN
END
GO
</code></pre>
You would call it like this:
<pre><code>
Select * From SplitString('Hello John Smith',' ')
</code></pre> |
Here is a UDF which will do it. It will return a table of the delimited values, haven't tried all scenarios on it but your example works fine.
<pre><code>
CREATE FUNCTION SplitString
(
-- Add the parameters for the function here
@myString varchar(500),
@deliminator varchar(10)
)
RETURNS
@ReturnTable TABLE
(
-- Add the column definitions for the TABLE variable here
[id] [int] IDENTITY(1,1) NOT NULL,
[part] [varchar](50) NULL
)
AS
BEGIN
Declare @iSpaces int
Declare @part varchar(50)
--initialize spaces
Select @iSpaces = charindex(@deliminator,@myString,0)
While @iSpaces > 0
Begin
Select @part = substring(@myString,0,charindex(@deliminator,@myString,0))
Insert Into @ReturnTable(part)
Select @part
Select @myString = substring(@mystring,charindex(@deliminator,@myString,0)+ len(@deliminator),len(@myString) - charindex(' ',@myString,0))
Select @iSpaces = charindex(@deliminator,@myString,0)
end
If len(@myString) > 0
Insert Into @ReturnTable
Select @myString
RETURN
END
GO
</code></pre>
You would call it like this:
<pre><code>
Select * From SplitString('Hello John Smith',' ')
</code></pre>
Edit: Updated solution to handle delimters with a len>1 as in :
<pre><code>
select * From SplitString('Hello**John**Smith','**')
</code></pre> |
While semi-related to your question, it does not entirely fit the Powershell NetCmdlets motif. But I wanted to post it anyhow as I use it daily and it may help others. Simply making shift-control-c key combo into displaying the visual studio command prompt. |
> PDF has the disadvantage of requiring the Adobe Reader
I use [Foxit Reader][1] on Windows at home and at work. A lot smaller and very quick to open. Very handy when you are wondering what exactly a80000326.pdf is and why it is clogging up your documents folder.
[1]: http://www.foxitsoftware.com/pdf/rd_intro.php |
How can I improve the edit-compile-test loop when developing a SharePoint workflow? |
|sharepoint|workflows| |
Recently I had to develop a SharePoint workflow, and I found the experience quite honestly the most painful programming task I've ever had to tackle. One big problem I had was the problems I encountered when I had to step through it in the debugger.
There's an article on how to debug a SharePoint workflow [here][1] that tells you how to set breakpoints etc. This involves copying the .pdb file into the GAC alongside the .dll file containing your workflow. You have to do this from a command prompt (or a batch file) because Windows Explorer doesn't let you view the relevant subdirectory of c:\windows\assembly.
However, if you do this, the next time you try to deploy the workflow from within Visual Studio, it complains that it can't be deployed because "the file may not be signed" and if you attempt to copy the new version of the dll into the GAC, it tells you that the .dll file is locked.
I've found that some of the time, you can get round this by doing an iisreset, but on other occasions you have to restart Visual Studio and there have been frequent times when I've even had to reboot the computer altogether because some mystery process has locked the file. When I don't use the debugger, on the other hand, everything works just fine.
Does anyone know of a simpler way of debugging workflows than this?
[1]: http://www.andrewconnell.com/blog/archive/2008/06/11/SharePoint-Debugging-and-Logging-Tips-and-Tricks.aspx |
|sharepoint|workflow| |
For me, the concept of Haskell's algebraic data types always looked like polymorphism in OO-languages like C#.
Look at the example from [http://en.wikipedia.org/wiki/Algebraic_data_types][1]:
data Tree = Empty
| Leaf Int
| Node Tree Tree
This could be implemented in C# as a TreeNode base class, with a derived Leaf class and a derived TreeNodeWithChildren class, and if you want even a derived EmptyNode class.
(OK I know, nobody would ever do that, but at least you could do it.)
[1]: http://en.wikipedia.org/wiki/Algebraic_data_types |
Yeah, you're going to want to do
if( $_GET['destroy'] == 1 )
or
if( isset($_GET['destroy']) ) |
Javascript troubleshooting tools in IE |
|javascript|ie| |
I use Firebug and the Mozilla JS console like crazy, but every now and then run into an IE-only Javascript bug, which everyone knows are really hard to locate even though you know theyre there (ex: error on line 724, when your source html only has 200 lines!)
I would love to have a lightweight JS tool (a la firebug) for IE, something I can install in seconds on a clients PC if I run into an error and then uninstall. Some Microsoft tools take some serious download and configuration time.
ideas?
Cheers,
/mp |
|javascript|internet-explorer| |
Structure of Projects in Version Control |
I have worked with NSIS and getting past some of its minor complexities its a fantastic system. its free, offers tons of plugin ability and managed to do everything I needed to do. |
I don't know the details of the Sony network camera and the server side software. But what do you mean by web-server functionality - is that the UI that get served up to the users in form of a HTML page? Or is it something more, like a server capturing the video stream and transcoding it?
I think the direction you need to take is to first find the URL end-point of your video stream. Since it's a network camera I assume the camera has a built in IP-stack/HTTP server serving up the video stream. Once you have that feed you probably have to transcode it into a video format consumable by Silverlight. There are multiple tools you can use, but for Silverlight the preferred tool Microsoft Expression Encoder. It supports live transcoding of webcam video streams. I think it supports both Direct Show devices as well as video streams. |
One think to remember is the following ASP.NET directive.
<%@ MasterType attribute="value" [attribute="value"...] %>
[MSDN Reference][1]
It will help you when referencing this.Master by creating a strongly typed reference to the master page. You can then reference your ListView without needing to CAST.
[1]: http://msdn.microsoft.com/en-us/library/ms228274.aspx |
Of the suggestions so far, I'm partial to Kevin's, but it doesn't need to be absolute. I see a couple different options to use with __autoload.
1. Put all class files into a single directory. Name the file after the class, ie, `classes/User.php` or `classes/User.class.php`.
2. Kevin's idea of putting models into one directory, controllers into another, etc. Works well if all of your classes fit nicely into the MVC framework, but sometimes, things get messy.
3. Include the directory in the classname. For example, a class called Model_User would actually be located at `classes/Model/User.php`. Your __autoload function would know to translate an underscore into a directory separator to find the file.
4. Just parse the whole directory structure once. Either in the __autoload function, or even just in the same PHP file where it's defined, loop over the contents of the `classes` directory and cache what files are where. So, if you try to load the `User` class, it doesn't matter if it's in `classes/User.php` or `classes/Models/User.php` or `classes/Utility/User.php`. Once it finds `User.php` somewhere in the `classes` directory, it will know what file to include when the `User` class needs to be autoloaded. |
For C and Objective-C, you can also use the [LLVM][1] [Clang][2] static analyzer.
It's Open Source and under active development.
[1] http://LLVM.org
[2] http://clang.LLVM.org |
For C and Objective-C, you can also use the [LLVM][1]/[Clang][2] [Static Analyzer][3].
It's Open Source and under active development.
[1]: http://llvm.org/ "LLVM - Low Level Virtual Machine"
[2]: http://clang.llvm.org/ "LLVM Clang C & Objective-C Compiler"
[3]: http://clang.llvm.org/StaticAnalysis.html "Clang Static Analyzer"
|
You can mark variables as nullable like this:
$!variable
If $variable is null, nothing will be rendered. If it is not null, its value will render as it normally would. |
HSL and HSV are better for human color perception. According to [Wikipedia][1]:
> It is sometimes preferable in working with art materials, digitized images, or other media, to use the HSV or HSL color model over alternative models such as RGB or CMYK, because of differences in the ways the models emulate how humans perceive color. RGB and CMYK are additive and subtractive models, respectively, modelling the way that primary color lights or pigments (respectively) combine to form new colors when mixed.
![Graphical depiction of HSV][2]
![HSL arranged as a double-cone][3]
[1]: http://en.wikipedia.org/wiki/HSL_and_HSV
[2]: http://upload.wikimedia.org/wikipedia/commons/thumb/e/e0/HSV_cylinder.png/200px-HSV_cylinder.png
[3]: http://upload.wikimedia.org/wikipedia/en/thumb/d/d3/Color_cones.png/200px-Color_cones.png |
One method that might work for some cases would be to take the sql string that would run if you naively used the form data and pass it to some code that counts the number of statements that would actually be executed. If it is greater than the number expected, then there is a decent chance that an injection was attempted, especially for fields that are unlikely to include control characters such as username.
Something like a normal text box would be a bit harder since this method would be a lot more likely to return false positives, but this would be a start, at least. |
One little thing to keep in mind: In some countries (i.e. most of Europe), people do not have static IP Addresses, so blacklisting should not be forever. |
You can try [TeraCopy](http://www.codesector.com/teracopy.php) or [RoboCopy](http://en.wikipedia.org/wiki/Robocopy). |
It sounds like a backup-style tool may be what you're looking for.
I've been using [SyncBack][1] (one of the versions is free). You could also try out [MS SyncToy][2] which tries to make moving, copying, syncing, etc. easy.
If you really do copy just random files at random times, you could try [Total Copy][3] which has the added benefit of working well over a network (pause, resume, etc.).
[1]: http://www.2brightsparks.com/downloads.html
[2]: http://en.wikipedia.org/wiki/SyncToy
[3]: http://www.ranvik.net/totalcopy/ |
Now that I think about it, a Bayesian filter similar to the ones used to block spam might work decently too. If you got together a set of normal text for each field and a set of sql injections, you might be able to train it to flag injection attacks. |
You really need to use a file Sync tool, like [SyncBackSE][1], [MS SyncToy][2], or even something like [WinMerge][3] will do the trick.
I prefer SyncBack as it allows you to set up very explicit rules for just about every possible case and conflict, at least more so than the other two.
With any of these you won't have to keep clicking all the pop-ups and you can verify, without a doubt, that the destination is exactly the same as the source.
[1]: http://www.2brightsparks.com/syncback/syncback-hub.html
[2]: http://www.microsoft.com/downloads/details.aspx?familyid=C26EFA36-98E0-4EE9-A7C5-98D0592D8C52&displaylang=en
[3]: http://winmerge.org/ |
The physical database size doesn't matter. The number of records don't matter.
In my experience the biggest problem that you are going to run in to is not size, but the number of queries you can handle at a time. Most likely you are going to have to move to a master/slave configuration so that the read queries can run against the slaves and the write queries run against the master. However if you are not ready for this yet, you can always tweak your indexes for the queries you are running to speed up the response times. Also there is a lot of tweaking you can do to the network stack and kernal in Linux that will help.
I have had mine get up to 10G, with only a moderate number of connections and it handled the requests just fine.
I would focus first on your indexes, than have a server admin look at your OS, and if all that doesn't help it might be time for a master/slave configuration. |