Copy JSON file and load from user database - sql

Im working on a project that will be used in a closed environment for events within a school.
The basic idea is to have a JSON file with a bunch of different objects that users who will login through a website will be able to "collect"
{
"Object Type": {
"Ball": {
"Red": {
"Collected": false
},
"Blue": {
"Collected": false
},
"Yellow": {
"Collected" : false"
}
}
}
}
The problem im running into is how to store this JSON file "unique" for each user.
If a user logs in they should be able to edit their collection and when they logout it's saved. Each user should have a unique collection that has the same "base template".
Both the amount of objects and users will be upwards in the hundreds.
Im writting the website itself in ASP.NET but cant seem to find any good solutions how to tackle this problem.
The user login will be stored in a SQL server.
Anyone who got experience with similar problems who managed to find a solution? Or would it just be better to change language and datastorage structure.

Related

How to set proxy through setting.json in JetBrains Toolbox?

When I click change proxy setting button on this app, it will crash. And I realize that I can set proxy through settings.json. But in this file it shows like below.
{
"autostart": true,
"install_location": "D:/Jetbrains/ToolBox",
"privacy_policy": {
"eua_accepted_version": "1.1"
},
"proxy": null
"shell_scripts": {
"enabled": false
},
"statistics": {
"allow": true
},
"update": {
"filter": {
"quality_filter": {
"order_value": 10000
}
}
}
}
I got no idea about proxy:null, there is no sample to help me figure out how to set proxy through json. So what's the right properties about proxy in this file? Could anybody give a sample?
It takes a dictionary where the keys are the same variable names you'd define in your shell and the values are the values you'd assign them. For instance http_proxy, https_proxy, no_proxy. Here is an example of what I have in my settings.json:
"proxy": {
"http_proxy": "http://my.proxy.url:8888",
"https_proxy": "http://my.proxy.url:8888",
"no_proxy": "localhost,127.0.0.1,localaddress,.localdomain.com"
},
I also tried manually editing the .desktop file's Exec line by adding the proxy environmental variables and while that works the first launch, the .desktop file is overwritten each time the application is launched so it won't work on subsequent launches and won't work if you have the application launch on login. Setting the proxy in the settings.json is the only way to make it work without manual intervention every time it's launched.
This is not documented anywhere that I could find and I wasted way more time than I'd liek to admit before I tried this solution. I'm glad it was as simple as it is but how hard would that be to document? It may seem intuitive, but how often have we all been burned by something where the intuitive and logical answer was not the actual implementation.

Navigating site (including forms) with PhantomJS

I'm trying to automate an application that uses form security in order to upload a file and then scrape data from the returned HTML.
I started out using the solution from this question. I can define my steps and get through the entire workflow as long as the last step is rendering the page.
Here are the two steps that are the meat of my script:
function() {
page.open("https://remotesite.com/do/something", function(status) {
if ('success' === status) {
page.uploadFile('input[name=file]', 'x.csv');
page.evaluate(function() {
// assignButton is used to associate modules with an account
document.getElementById("assignButton").click();
});
}
});
},
function() {
page.render('upload-results.png');
page.evaluate(function() {
var results = document.getElementById("moduleProcessingReport");
console.log("results: " + results);
});
},
When I run the script, I see that the output render is correct. However, the evaluate part isn't working. I can confirm that my DOM selection is correct by running it in the Javascript console while on the remote site.
I have seen other questions, but they revolve around using setTimeout. Unfortunately, the step strategy from the original approach already has a timeout.
UPDATE
I tried a slightly different approach, using this post and got similar results. I believe that document uses an older PhantomJS API, so I used the 'onLoadFinished' event to drive between steps.
i recomend you use casperjs or if you use PJS's webPage.injectScript() you could load up jquery and then your own script to do form input/navigation.

Array store Sencha Touch 2

While building my first mobile app using sencha touch 2 some questions got in my way and I can't seem to find their answer.
Where should an app configuration be stored (theme, language, font size ). I was thinking
to count the data from a store and if bigger than 0 work on that data otherwise add data( this would happen only the first time application is opened or localstorage cleared..). There are other options for this kind of thing(things like an array which will be changed when user is interacting with the app) ?
I need to use in my application around 100 images. I don't know what options I have here to embed the images into app. Saw lots of examples loading image from external server but not sure if there is an option for packing them with the app.
If I had an array with a name(key) and the image url(value), where should this array be ? in a json file and use an ajax load each time a need a name in there ?
Thanks.
Let me suggest few options:
1- App configuration : If app configuration is like set of constant values which won't change by user interaction you can create a file (e.g. properties.js) and load it on application load.
Properties = {
SERVICE_URL : 'http://mycompany.com/api',
PAGE_SIZE : 20
}
and to load it you just have to edit app.json
"js": [
{
"path": "touch/sencha-touch.js",
"x-bootstrap": true
},
{
"path": "resources/data/properties.js"
}
]
If you want to control these values then you can keep it on your server and give its URL as "path" in app.json
2- There is always option of packaging images with your app, just like all the icon & startup images are packaged but its not suggested because it increases size of your deployable and people with slow internet connections and low end devices might skip installing it if size it too large.
3- No need to load the JSON file every time you need it, you can cache the data in global variable after first load and keep referring to the array whenever required. Now where to define global variable is another interesting discussion with people suggesting lot of things but I prefer to have a singleton class which can keep all the global functions & variables. See this thread to understand how : Where do I put my global helper functions if they are needed before Ext.application() is being executed?
For Text we can Try like this
var A_address=Ext.getCmp('address').getValue(); //get the value
localStorage.setItem("Adult1_select1",A_select1); // assign localstore
var web_arrayTotalPAssengers=[];
web_arrayTotalPAssengers.push(localStorage.getItem("web_TotalPassengers"));
console.log(web_arrayTotalPAssengers);
// push the values in array...
Ext.Ajax.request({
url:'http:/...........',
method:'POST',
disableCaching: false,
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
jsonData: {
origin:Ext.decode(web_arrayTotalPAssengers), //decode and send
}
success:function(response)
{
console.log(response);
console.log("Success");
},
failure : function(response)
{
console.log("Failed");
}

Check whether facebook user likes my app

I've read several sources now but did not find a solution: I'm using Facebook C# SDK with ASP.net 4 and VB.net 2010. I have a Facebook Canvas application. I'm using Canvas Auth.Authorize and it works fine. Now I want to know whether the currently logged in user already likes my app. How could I do that?
'SignedRequest' does not seem to work because according to Facebook Documentation "This field is only present if your app is being loaded within a Page Tab".
graph/user/likes is also not an option because I don't want to ask the user to grant access for my app to all his likes.
But the Facebook Plugin is able to differ whether the current user likes my app or not, so I'm quite optimistic that there is a way which I just did not find yet.
Many thanks!
You can use the graph API to call the users likes. Instead of requesting all of the likes simply request the single one you want.
https://graph.facebook.com/userId/likes/appId
If you the user has liked the page the result will return details about the page. For example:
{
"data": [
{
"name": "Microsoft Office Web Apps",
"category": "Software",
"id": "121883824529155",
"created_time": "2012-03-14T06:48:47+0000"
}
],
"paging": {
"next": "https://graph.facebook.com/me/likes/121883824529155?format=json&limit=5000&offset=5000&__after_id=121883824529155"
}
}
If the user has not liked the page you will receive empty data.
{
"data": [
]
}
With the Facebook C# SDK you would make this request as follows:
var client = FacebookClient("access_token_here");
dynamic result = client.Get('/me/appId');
if (result.data.Length == 1) {
// User has liked page
}

How can i use the port.postmessage to send info from the background page to the content script in a Google Chrome extension

I've been able to send data from the background page to the content script. but this is done using sendrequest(). I will need to send data back and forth so I'm trying to figure out the correct syntax for using the port.postmessage from background page to content script. I have already read, several times, the google page on Messaging and I don't seem to get it. I even copied the code directly from the page and tested with no result. All I'm trying to do for now is send data from background page to content script using connect as opposed to sendrequest. The response from the content script I will deal with later as code with this response has been the main thorn. I just want to understand the process one step at a time without the extra knowledge of sending a response back.
I'm not sure if this contravenes the rules of this board but can someone PLEASE give me an example of some code to do this (background page and content script excerpt, the background page is the sender).
I've asked for assistance several times on this site only to be told to read the documentation or check out sites I've already visited.
If you just want any example of opening a port from the extension to a content script, here's the simplest I can think of. The background just opens a port and sends "Hello tab!" over the port, and the content script sends a message to the background any time you click on the webpage.
I think this is pretty simple, so I don't know why you are so stressed. Just make sure that the content tab is already listening when the background tries to connect (I do this by waiting until the "complete" event).
manifest.json:
{
"name": "TestExt",
"version": "0.1",
"background_page": "background.html",
"content_scripts": [{
"matches": ["http://localhost/*"], // same as background.html regexp
"js": ["injected.js"]
}],
"permissions": [
"tabs" // ability to inject js and listen to onUpdated
]
}
background.html:
<script>
var interestingTabs = {};
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
// same as manifest.json wildcard
if (changeInfo.url && /http:\/\/localhost(:\d+)?\/(.|$)/.test(changeInfo.url)) {
interestingTabs[tabId] = true;
}
if (changeInfo.status === 'complete' && interestingTabs[tabId]) {
delete interestingTabs[tabId];
console.log('Trying to connect to tab ' + tabId);
var port = chrome.tabs.connect(tabId);
port.onMessage.addListener(function(m) {
console.log('received message from tab ' + tabId + ':');
console.log(m);
});
port.postMessage('Hello tab!');
}
});
</script>
injection.js:
chrome.extension.onConnect.addListener(function(port) {
console.log('Connected to content script!');
port.onMessage.addListener(function(m) {
console.log('Received message:');
console.log(m);
});
document.documentElement.addEventListener('click', function(e) {
port.postMessage('User clicked on a ' + e.target.tagName);
}, true);
});
Detailed documentation and easy (the most basic) examples shown in the documentation page.
Plus, a quick search in stackoverflow will allow you to see many similar questions with detailed answers.