Saturday, 31 August 2013

Should I make multiple SQLite databases for better concurrency?

Should I make multiple SQLite databases for better concurrency?

I'm very new to SQL and relational databases (just started learning last
week) and I'm in the process of upgrading my website and currently keep
all my data in XML files. It works, but the new site would be better
suited from what I hear a relational database can do, and it looks like
SQLite is best for me. One of my concerns is concurrency, even though 99%
of the data will be read-only (which I understand SQLite is pretty good
at) 99% of the time. Other things, like page view counters for certain
pages will constantly require small writes. I'm still learning database
design and want to do it right. Would it make sense to make separate
databases for things that get written to a lot, that way making the main
database far less susceptible to concurrency issues? Is it possible to do
a "foreign key" type reference (I still haven't used foreign keys yet, but
think I understand them) across databases? As each view count would point
to some primary key in the main database. Thanks for any help!

Difference between Nil and nil and Null in Objective-C

Difference between Nil and nil and Null in Objective-C

I am a relatively experienced iOS developer, however one thing has always
bothered me, what is the difference between Nil(Capital) and
nil(lowercase) and NULL (if any) in terms of performance and usage? I am
absolutely sure that there is a difference between them otherwise why
would they be defined as separately in the first place...

Cannot connect to SQL Server 2012

Cannot connect to SQL Server 2012

I'm trying to connect to a SQL Server 2012 database using C#, both the
server and program are on the same computer. When I try to connect I get
an exception:
A network-related or instance-specific error occurred while establishing a
connection to SQL Server. The server was not found or was not accessible.
Verify that the instance name is correct and that SQL Server is configured
to allow remote connections. (provider: SQL Network Interfaces, error: 25
- Connection string is not valid)
There is an inner exception simply saying {"The parameter is incorrect"}.
I'm trying to connect using this
SqlConnection sql = new
SqlConnection("Server=(local)\\MSSQLSERVER;Database=Test;User
ID=logger;Password=logger;Trusted_Connection=False");
sql.Open();
I have a SQL login called logger with the same text as the password and it
is mapped the database Test. I believe I have the server set up to take
remote logins.
Any ideas as to what I am missing?

Android - error opening file just created

Android - error opening file just created

I'm new to android developement and trying to do some file IO. Whenever I
run this block of code:
File meta = new File(context.getAppContext().getFilesDir(),"meta");
meta.mkdirs();
File dir = new File(meta,"subdir");
File imageFile = new File(dir,"filename");
Log.d("test",imageFile.getAbsolutePath());
FileOutputStream outputStream = new FileOutputStream(imageFile);
I get this error:
java.io.FileNotFoundException:
/data/data/com.example.android.networkusage/files/meta/Greg and The
Morning Buzz/artwork30.jpg: open failed: ENOENT (No such file or
directory)
at libcore.io.IoBridge.open(IoBridge.java:406)
at java.io.FileOutputStream.<init>(FileOutputStream.java:88)
at java.io.FileOutputStream.<init>(FileOutputStream.java:73)
at
com.example.android.networkusage.Podcast.downloadArtworkFromUrl(Podcast.java:117)
at com.example.android.networkusage.Podcast.<init>(Podcast.java:93)
at com.example.android.networkusage.JSONParser.parse(JSONParser.java:113)
at
com.example.android.networkusage.NetworkActivity.loadXmlFromNetwork(NetworkActivity.java:240)
at
com.example.android.networkusage.NetworkActivity.access$100(NetworkActivity.java:65)
at
com.example.android.networkusage.NetworkActivity$DownloadXmlTask.doInBackground(NetworkActivity.java:203)
at
com.example.android.networkusage.NetworkActivity$DownloadXmlTask.doInBackground(NetworkActivity.java:198)
at android.os.AsyncTask$2.call(AsyncTask.java:264)
at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
at java.util.concurrent.FutureTask.run(FutureTask.java:137)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
at java.lang.Thread.run(Thread.java:856)
Caused by: libcore.io.ErrnoException: open failed: ENOENT (No such
file or directory)
at libcore.io.Posix.open(Native Method)
at libcore.io.BlockGuardOs.open(BlockGuardOs.java:110)
at libcore.io.IoBridge.open(IoBridge.java:390)
... 16 more
The log even prints out the file's path as directed, so the file must
exist! Why is this happening?
Also, my app has internal and external write priviledges.

PHP SimpleXML doesn't output anything

PHP SimpleXML doesn't output anything

I'm trying to read an XML file that I created. I'm using this code, but
getting nothing out except 'the file was loaded successfully'. I've tried
xpath and many others, but it just doesn't output. It is possible there is
something wrong with my XML because I created the file by hand and I've
never made an XML file before.
Ultimately, my goal is to be able to read an extension attribute and get
the description, class, and icon.
<?php
if(!$xml = simplexml_load_file('formats.xml')) {
echo 'the file was loaded successfully';
print_r($xml);
}
else {
echo 'the file was not loaded';
}
?>
Here is the XML:
<?xml version="1.0"?>
<group class="doc" icon="./.images/doc.png" />
<type extension="doc" description="Legacy Word Document" />
<type extension="docx" description="XML Word Document" />
<type extension="ppt" description="Legacy PowerPoint" />
<type extension="pptx" description="XML PowerPoint" />
<type extension="pps" description="Legacy PowerPoint Show" />
<type extension="ppsx" description="XML PowerPoint Show" />
<type extension="docm" description="Macro Enabled Word Document" />
<type extension="dot" description="Legacy Word Template" />
<type extension="dotx" description="XML Word Template" />
<type extension="dotm" description="Macro Enabled Word Template" />
<type extension="log" description="A Log File" />
<type extension="msg" description="A Message File" />
<type extension="odt" description="OpenOffice Document" />
<type extension="pages" description="Apple Pages Document" />
<type extension="rtf" description="Rich Text Format" />
<type extension="tex" description="LaTeX Document" />
<type extension="wpd" description="Word Perfect Document" />
<type extension="ini" description="Settings File" />
<type extension="cfg" description="Config File" />
<type extension="conf" description="Config File" />
<type extension="nfo" description="Information File" />
<type extension="inf" description="Autorun File" />
<type extension="wps" description="Works Document" />
</group>
<group class="video" icon="./.images/video.png" />
<type extension="asf" description="Advanced Streaming Format" />
<type extension="asx" description="Windows Media Playlist" />
<type extension="avi" description="Audio-Video Interleave" />
<type extension="flv" description="Flash Player Video" />
<type extension="mkv" description="Matroska Video" />
<type extension="mov" description="Apple Movie" />
<type extension="mp4" description="MPEG 4 Video" />
<type extension="mpg" description="MPEG Video" />
<type extension="rm" description="RealMedia Video" />
<type extension="srt" description="Subtitles File" />
<type extension="swf" description="Flash Animation" />
<type extension="vob" description="DVD Video File" />
<type extension="wmv" description="Windows Media Video" />
<type extension="mpeg" description="Motion Picture Experts Video" />
</group>

Memory leak (igraph, watts.strogatz.game, get.all.shortest.paths)

Memory leak (igraph, watts.strogatz.game, get.all.shortest.paths)

I try to make a quite simple computation but I get an out of memory
message whose origin is not clear to me. Here is what I want: for the
small-world model (watts.strogatz.game) and several p-values I create
nsamp many graphs and compute the distance between the first node and the
opposite node at n/2. When nsamp = 1, everything works fine. Setting it to
100 or larger gives an "out of memory" error right in the first round
(i=1, j=5), i.e., for the smallest p-value (0.01). Setting nsamp=10 gives
no error (huh?? Shouldn't that include i=1, j=5?). I tried to explicitly
remove all the larger objects (graph, len) but to no avail. Any ideas
here? Here is the code:
require(igraph)
probs <- c(1:25)*0.01
n = 1000
target <- n/2
nsamp = 100
for(i in c(1:length(probs))){
for(j in c(1:nsamp)){
graph <- watts.strogatz.game(dim=1, size=n, p=probs[i], nei=4)
shortest.paths(graph, v=V(graph)[1], to=V(graph)[target])
len <- get.all.shortest.paths(graph, from=V(graph)[1])
rm(graph)
#The number of shortest paths between 1 and target can be found in
numbPathsBetw1AndTarget <- len$nrgeo[target]
#In len$res there are all shortest paths between node 1 and all other
#nodes. It comes as a list which at each point contains a vector of
#so we need to use lapply to find out which of
#the lists are of interest to us.
lengths <- unlist(lapply(len$res, function(x) length(x)))
rm(len)
}
}
I am aware that I can increase the memory, but it bugs me that for nsamp
being small everything is fine. It seems to be a memory leak but I do not
there where it comes into play.
Edit: it is so unreproducible that I suspect it is not a memory leak but
rather a bad configuration of the graph. It always happens for i=1 but for
different j. Thus: is there an intrinsic, upper limit on the diameter of
the graph to apply get.all.shortest.paths or on the number of shortest
paths?

Friday, 30 August 2013

How do I position a div on top of another div

How do I position a div on top of another div

The post on my website are set to show information regarding the post when
the mouse hovers over it.
Currently when I hover over a post the information shows to the right, and
I would like it to show on top of the post. I want to be able to margin
the information to show ontop of the post in the center but nothing I
input is working. After everything I tried didn't work I went back and set
them to blank and that still didn't work. You can see a live version at
http://fallbackryleighamor.tumblr.com/
This is the current css. Any idea how I can edit it to make it work?
#info #date{ color:#000; border: 2px #000 solid;
text-transform: uppercase; letter-spacing: 2px; font: 10px Consolas;}
#info a{ color: #000;}
#date a { width: 280px; color: #000;}
#posts{ position:;}
#date #info{position:;} #date #info{float:;}
{background: rgba(0, 0, 9, 0.1); float:left; width: auto; height: auto;
margin-top: ;}
#textpost #photopost #photosetpost #quotepost #quotelink #audiopost
#videopost{background: rgba(0, 0, 9, 0.1); float:left; width: auto;
height: auto; margin-top: ;}
#date { display:none;}
#posts:hover #date {display:block;}
#textpost:hover #photopost:hover #photosetpost:hover #quotepost:hover
#quotelink:hover
#audiopost:hover #videopost:hover{display:block;}
#date #info{
margin-top:0px;
margin-bottom:0px;
margin-right:0px;
margin-left:0px;
}
#date #info{
padding-top:0px;
padding-bottom:0px;
padding-right:0px;
padding-left:0px;
}
#date #info{
z-index:;}