How to download a file with resume support? [closed] - go

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Am using golang as a programming tool of choice.
What i wanted to write is a program that downloads large files with resume support utilising range requests in the http headers
something similar to aria2c.

To do that you should study the part 14.16 — Content-Range — of the RFC document describing the HTTP/1.1 protocol and then apply that knowledge to manipulate the set of HTTP headers sent when the client request is executed — see the documentation and examples there.
To calculate the range to request, to continue downloading, you should get the current file's size. This can be found in the results returned by the Stat() function which can be called on an opened file — *os.File returned by a call to os.Open().
You should open your file in append mode and then use something like io.Copy() to stream the data from the Body HTTP response member to the file object.
Do your own research on how to read data from HTTP responses in Go — they are abundant on the Internet.

Related

Design patterns for shared state with many to many streaming [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
I'm writing an online whiteboard application for fun, where multiple users view the same whiteboard and can draw on it. I'm using websockets (vanilla JS on the frontend, Scala on the backend), and right now am essentially just broadcasting mouse events from one user to the rest of the users, and rendering the image client-side.
However, this results in a transient shared state, whereas I would like to have users be able to hop on at any time and see the preserved shared state. I'm thinking this will probably require having shared rendering code on the backend and the frontend, so that clients render events as they stream but the server can send raw image data when clients associate.
So my question here is: what are some other design patterns I should be aware of for this kind of project? This is a for fun/learning project, so this is an open-ended question, but I'll accept an answer that contains some useful references for this kind of data flow.
So my question here is: what are some other design patterns I should
be aware of for this kind of project?
You don't have to have rendering code on the server. You can just save all the accumulated events that led to the current whiteboard and send those to a new client and let the new client render the whiteboard for itself as if they were listening when all the events originally happened.
If that's more data than is practical, then you can compress raw events. For example a straight or nearly straight line segment does not need all the intervening mouse positions, it really just needs the first and last position of the segment.

How does Sticky Notes work? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
Recently I attended an interview, where the interviewer asked me the following questions in technical face to face interview:
How does Sticky Notes works?
How Windows is able to preserver the data even though it is not saved explicitly?
How the data is preserved even when the system crashes?
I've no idea how does it works. Tried googling, but I couldn't find any useful information.
Can anyone explain or give some information?
I agree with #Vii's response. He has the right information about where the file is stored.
I have found some forensic background on this file here:
http://www.forensicswiki.org/wiki/Sticky_Notes
It seems like the SNT file has 3 datastreams, 0,1 and 3. Stream 0 stores information in RTF form and Steam 3 stores the actual text in Unicode format.
The Root Entry of the storage stream has a timestamp associated with it and you can use tools like MiTec Storage Viewer, Sticky7List to view the creation and modification times associated with the file. You can create a sticky note and observe when it creates the datastream and modify the sticky note and monitor how it modifies the file.
Some helpful references:
http://www.pcworld.com/article/191453/sticky_notes.html
https://superuser.com/questions/396698/how-to-retrieve-contents-of-stick-notes-directly-from-file-system
http://www.forensicswiki.org/wiki/Sticky_Notes
http://computer-forensics.sans.org/blog/2010/10/19/digital-forensics-stuck-stickies-2
http://windowsir.blogspot.com/2011/08/sticky-notes-analysis.html
Sticky notes are written to a file which you can find at '%appdata%\Microsoft\Sticky Notes\StickyNotes.snt' and since there is not an explicit 'save' option, it should be flushing the content to that file as you write it and hence the data is preserved in case of a system crash.

Raw data in analytics [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to have the data in my site individually. For example: visitant 1 visited page 1, page 2, page 3, at time x,y,z.
How can i get this data in analytics?
You cannot see data for individual visitors in GA (and trying to do so would violate Googles Terms of Service).
You can redirect the tracking calls to your own server and write a script to parse for visitor data, see me answer here:
What would database-schema/database-design look like for google analytics?
(Those methods served for compatibility with the Urchin analytics software - since support for Urchin was dropped it might be that those method will be dropped at some point in the future).

Secure handling of uploaded images [closed]

Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I was reading this article on how to secure my website from attacker i stopped on these line and i was trying to figure out what they mean by it
you cannot rely on the file extension or the mime type to verify that the file is an image
as these can easily be faked. Even opening the file and reading the header, or using
functions to check the image size are not full proof. Most images formats allow storing a
comment section which could contain PHP code that could be executed by the server.
What do they mean by Most images formats allow storing a comment section ?
link : http://www.netmagazine.com/features/10-essential-security-tips-protect-your-site-hackers
Well, just like you can store a comment inside an MP3 file, a lot of image formats also make space for a comment. A comment is just a short bit of text to describe the file.
Lots of applications now are able to extract just a little bit of information from a lot of different file types, and the risk is that your PHP code, while extracting the comment from an image file (a relatively easy task) may run the risk of incorporating any PHP code stored in the comment into your PHP code.
Essentially, this exploited a bug in PHP, kind of similar to a SQL injection exploit. Most HTTP servers, however, when sending images, send them as binary so you needn't worry too much about image files on web-pages being a threat.
Just make sure that any image work you do doesn't try and interpret the comment section, instead pass it through a formatter/sanitizer to ensure that the content of an images' comment section, if retrieved, is not just inserted into the HTML at the point of displaying it.

google ajax api results differ from normal search, why? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I read about the Ajax API here Scraping/Parsing Google search results in Ruby
For some reason, I get completely different results from the same query when using the Ajax API than I do from normal search. Is there a simple explanation?
here are the two:
http://www.google.com/search?hl=en&rls=en&q=site%3Ahttp%3A%2F%2Ftwitter.com%2F+following&aq=f&oq=&aqi=0
http://ajax.googleapis.com/ajax/services/search/web?v=1.0&hl=en&rls=en&q=site%3Ahttp%3A%2F%2Ftwitter.com%2F+following&aq=f&oq=&aqi=0
both have parameters hl=en&rls=en&q=site%3Ahttp%3A%2F%2Ftwitter.com%2F+following&aq=f&oq=&aqi=0
run at the same time, they never give me the same results, often they're very different (depending on the search parameters.
what's going on?
Also, the
I'm guessing here, but usually if you do a google search using your regular account and have the history enabled, google will use your previous search to give you more accurate results. There are a bunch of things like that that may cause differences between searches with the exact same keyword(s)
The Axaj API is suspected to offer slightly different results to avoid the automatic harvesting of search result (SERP) info.
This is the same reason they only return 8 results per page and upto 8 pages via their AJAX api.
In principal they don't want people collecting this data, as it is usually used for SEO purposes in an attempt to coerce certain sites higher unduly.

Resources