Thursday, 8 August 2013

Is it possible to prevent a page being loaded using XHR?

Is it possible to prevent a page being loaded using XHR?

I want to transmit sensitive information in say the index.html which
should only be accessible from JavaScript during the load time of the
page. Afterwards the JavaScript on the page should not be able to access
that data.
I can easily remove the sensitive data from the DOM on load but I also
need to prevent the page being loaded using XMLHTTPRequest or by scraping
it from an IFrame.
I can block the IFrame using the X-Frame-Options header and other frame
busting tricks but how can I block the page from being loaded using XHR?
The best solution I came up with is to serve the index.html with a CSP
header that doesn't include self in the connect-src directive but then I
can't XHR to any URL on my server and I need to white list all other
possible connect targets. There must be a better way to do it.

jQuery :gt selector with relative indexing

jQuery :gt selector with relative indexing

I have a <dl> list containing multiple <dd><ol>...</ol></dd> lists, each
with some number of <li> elements. I'm trying to select the last 3
elements of each <ol> list.
I can easily achieve it by using
$("dl dd ol").each(function(){
$elems = $("li:gt(2)",$(this));
});
I'm curious, is it possible to perform the same operation without using
$.each (i.e. only using selectors)? I've tried $("dl dd ol > li:gt(2)")
but it seems that :gt does not index relatively to the parent. Is there,
currently, any way to do this using only selectors?
jsFiddle

Wednesday, 7 August 2013

How to store images in document directory using core data?

How to store images in document directory using core data?

I referred example
http://klanguedoc.hubpages.com/hub/Core-Data-How-To-Store-and-Display-Images-in-a-Core-Data-iPhone-App-iOS-iPad#
and added jpg files but it did not work? Can anyone suggest what to do?

Reminder Website

Reminder Website

I am kind of new to web development but I enjoy learning by having real
projects. I am not completely sure what the best way is to do this, so
before I start the wrong way I ask you guys! :) I want to have a site
where you can choose a tv show and give your email address and when there
was a new episode on tv you get notified via mail. So what I would
probably try: -A email database with the info which series the adress is
subscribed to -A database for the show when the date of the next episode
is -A service/function to send out a mail on this date: cronjobs? But how
to manage so many? I am kind of New to.cronjobs Only php+mysql pls, no
python or whatever available Please give me some hints :) Sorry for my bad
English I'm.from Germany Ben

How to silence 'Expected a type' Xcode compiler warnings?

How to silence 'Expected a type' Xcode compiler warnings?

Is there any way to silence Xcode compiler warnings because of unknown
types like with @class? I defined a type in a single .h file that can be
reused throughout the app:
#ifndef Apsiape_InterfaceDefinitions_h
#define Apsiape_InterfaceDefinitions_h
#define COLOR_ALERT_RED [UIColor colorWithRed:1 green:0.3 blue:0.3 alpha:1]
...
typedef enum {
BYEdgeTypeNone = 0,
BYEdgeTypeTop,
BYEdgeTypeLeft,
BYEdgeTypeBottom,
BYEdgeTypeRight
} BYEdgeType;

Issues with inputstream outofmemory errors

Issues with inputstream outofmemory errors

I'm using the SpringFramework for Android to get my inputstreams.
@Override
public InputStream getImageStream(String url) {
InputStream is = new ByteArrayInputStream(template.getForObject(url,
byte[].class));
return is;
}
For the first few inputstreams its going ok. No Problems at all, but then,
I think it tries to get a very big inputstream. So then I get the
outofmemory error.
I see a lot of posts using something like the following code:
public byte[] readBytes(InputStream inputStream) throws IOException {
ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream();
int bufferSize = 1024;
byte[] buffer = new byte[bufferSize];
int len = 0;
while ((len = inputStream.read(buffer)) != -1) {
byteBuffer.write(buffer, 0, len);
}
byte[] byteArray= byteBuffer.toByteArray();
return byteArray;
}
The idea of this code is to read the inputstream in chunks right?
But the outofmemory error I'm getting is before I can even start the
readBytes. I tried putting resets everywhere...I thought maybe I should
clear the memory somewhere after readbytes or something. But I do not know
how and I don't know if that is the right way?
I think I'm having the basics wrong? I'm very new to android and java...
Is there a way of getting the InputStream another way? I also read
something about BufferedInputStream but I just can't think up of a way to
fit it in.
My goal is to store a blob of the image in the database. And my input is
the imgurl via oauth.
I can also call less quality versions of the inputstream through another
url. And then everything works... But I wanted to try it with the original
image url, because maybe later I want to have the ability to download an
original for printing the photo.

how to convert parent object with child object list into xml file using c#?

how to convert parent object with child object list into xml file using c#?

1.I have a parent table Class () and a child table subject . I have
created object of these classes and child object added as a list in parent
class . Now i want to read a parent table data using linq and convert it
into xml file . I am trying xml serialize for that . Below is my code.
1) ClassMaster cls = new ClassMaster();List clsList =
cls.FindAll().Where(t => t.ClassSymbol == "I").ToList();var serializer1 =
new XmlSerializer(cls.FindAll().GetType()); 2)ClassMaster cls = new
ClassMaster(); var stringwriter = new System.IO.StringWriter(); var
serializer = new XmlSerializer(cls.GetType());
serializer.Serialize(stringwriter, cls); But its throwing a exception in
line 3 "Cannot serialize member
'School.Objects.ClassMaster.classSubjectList' of type
'System.Collections.Generic.IList`1[[School.Objects.ClassWiseSubject,
School.Objects, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]'"
public class ClassMaster : GenericRepository { public virtual int ClassId
{ get; set; }
public virtual string ClassSymbol { get; set; }
public virtual string ClassName { get; set; }
public virtual IList<ClassWiseSubject> classSubjectList { get; set; }
}
public class ClassWiseSubject : GenericRepository<ClassWiseSubject>
{
public virtual int Id { get; set; }
public virtual int ParentID { get; set; }
public virtual int SerialNo { get; set; }
public virtual string SubjectCode { get; set; }
}
HBM config file :
<class name="SubjectMaster" table="tbl_SubjectMaster">
<id name="SubjectId" column="SubjectId" type="int">
<generator class="identity"></generator>
</id>
<property name="SubjectCode" column="SubjectCode" type="string"/>
<property name="SubjectName" column="SubjectName" type="string"/>
</class>
Thanks Surajit