Tuesday, 15 February 2011

php - How do I keep a local copy of a large JSON file updated? -



php - How do I keep a local copy of a large JSON file updated? -

i'm writing php-based website, , requires json table other website. it's relatively big file hardly ever gets updated, preferably i'd maintain local re-create , utilize that, rather request server same file.

but need latest version of json file, otherwise lot of links site break.

i'm new web-development i'm not sure how approach this. i've read on things redis , memcaching, i'm not sure if that's i'm looking or how working.

how can maintain local version of json file date, or there improve approach?

normally in situations these request updated re-create of file every x hours , store on server. in pracice: on every page load check how old file (filemtime()); if it's older x hours, download 1 time again , replace contents of cached files. x, number of hours, has adjusted accordingly frequency update original document. example, if know document updated every 6 hours, may want refresh every 2 hours (x=2), example.

you should prepared have outdated cache, however: @ moment cached file can x hours (e.g. if download file , webmasters replace 1 min later, cached file outdated x hours less minute).

there ways can improve process:

if file big, downloading while preparing web page in response visitor can bad idea. indeed, visitors hate waiting, , every ms more takes generate page more visitor go away , lose interest. there studies that (ironically, page took me few seconds load :) - , in meanwhile went tab type). solution: have background job periodically refreshes cached file. can cron; if don't have access cron, there other ways emulate in php. example, see the guys @ techcrunch came with. instead of downloading entire file every time, (if remote server supports it) first create request see if file has changed. that's possible if-modified-since header. see illustration this question. way create head http request , check lastly modified time. note not servers may back upwards these tricks (especially if remote server generating file dynamically). if supported, however, can decrease time interval between each request (the x above), since won't downloading whole file every time.

php json

wsgi - Upgrade to Django 1.7 - AppRegistryNotReady exception -



wsgi - Upgrade to Django 1.7 - AppRegistryNotReady exception -

i'm struggling trying create things work after upgrading django version 1.6.7 1.7. looks i'm not able focus on right matter. seek resume situation far.

thing is: if leave command django.setup() in wsgi.py file, when seek access website internal server error (500). looking @ logs, get:

[sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] mod_wsgi (pid=23258): target wsgi script '/home/thrasher/webapps/django/myproject.wsgi' cannot loaded python module. [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] mod_wsgi (pid=23258): exception occurred processing wsgi script '/home/thrasher/webapps/django/myproject.wsgi'. [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] traceback (most recent phone call last): [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] file "/home/thrasher/webapps/django/myproject.wsgi", line 16, in <module> [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] application = get_wsgi_application() [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] file "/home/thrasher/webapps/django/lib/python2.7/django/core/wsgi.py", line 14, in get_wsgi_application [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] django.setup() [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] file "/home/thrasher/webapps/django/lib/python2.7/django/__init__.py", line 21, in setup [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] apps.populate(settings.installed_apps) [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] file "/home/thrasher/webapps/django/lib/python2.7/django/apps/registry.py", line 78, in populate [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] raise runtimeerror("populate() isn't reentrant") [sun oct 12 12:38:50 2014] [error] [client 127.0.0.1] runtimeerror: populate() isn't reentrant

however, if comment django.setup() call, trying access website gets me stack trace:

environment: request method: request url: http://www.creepyvisions.it/ django version: 1.7 python version: 2.7.8 installed applications: ('django.contrib.auth', 'django.contrib.admin.apps.simpleadminconfig', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.admin', 'django.contrib.admindocs', 'myproject.archivio', 'sorl.thumbnail', 'django.contrib.sitemaps', 'rest_framework') installed middleware: ('django.middleware.common.commonmiddleware', 'django.contrib.sessions.middleware.sessionmiddleware', 'django.middleware.csrf.csrfviewmiddleware', 'django.contrib.auth.middleware.authenticationmiddleware', 'django.contrib.messages.middleware.messagemiddleware') traceback: file "/home/thrasher/webapps/django/lib/python2.7/django/core/handlers/base.py" in get_response 98. resolver_match = resolver.resolve(request.path_info) file "/home/thrasher/webapps/django/lib/python2.7/django/core/urlresolvers.py" in resolve 338. pattern in self.url_patterns: file "/home/thrasher/webapps/django/lib/python2.7/django/core/urlresolvers.py" in url_patterns 367. patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) file "/home/thrasher/webapps/django/lib/python2.7/django/core/urlresolvers.py" in urlconf_module 361. self._urlconf_module = import_module(self.urlconf_name) file "/usr/local/lib/python2.7/importlib/__init__.py" in import_module 37. __import__(name) file "/home/thrasher/webapps/django/myproject/urls.py" in <module> 33. url(r'^admin/', include(admin.site.urls)), file "/home/thrasher/webapps/django/lib/python2.7/django/contrib/admin/sites.py" in urls 260. homecoming self.get_urls(), self.app_name, self.name file "/home/thrasher/webapps/django/lib/python2.7/django/contrib/admin/sites.py" in get_urls 221. self.check_dependencies() file "/home/thrasher/webapps/django/lib/python2.7/django/contrib/admin/sites.py" in check_dependencies 159. if not apps.is_installed('django.contrib.admin'): file "/home/thrasher/webapps/django/lib/python2.7/django/apps/registry.py" in is_installed 223. self.check_apps_ready() file "/home/thrasher/webapps/django/lib/python2.7/django/apps/registry.py" in check_apps_ready 124. raise appregistrynotready("apps aren't loaded yet.") exception type: appregistrynotready @ / exception value: apps aren't loaded yet.

for sake of completion, code related wsgi:

myprojext.wsgi

import os import sys os.environ.setdefault("django_settings_module", "myproject.settings") django.core.wsgi import get_wsgi_application application = get_wsgi_application()

wgsi.py

import django django.core.handlers.wsgi import wsgihandler def get_wsgi_application(): #django.setup() homecoming wsgihandler()

things odd me, performed lot of searches in official django docs , in various forums, i'm still unable things work properly. suggestions much appreciated.

it turned out problem duplication, in installed_apps, of django.contrib.admin. looks root of problem. removed sec reference, uncommented django.setup() in wsgi.py , things became sunny , clear again. working fine.

django wsgi

sql - Save row in %ROWTYPE and delete it efficiently afterwards? -



sql - Save row in %ROWTYPE and delete it efficiently afterwards? -

this how currently:

declare tmp message%rowtype; begin; select * tmp [...] delete message m m.id = tmp.id; end;

i'm afraid db 2 queries here: 1 doing select , 1 delete. in case true - can create more efficient somehow? after row should deleted found in select query.

n.b. i'm storing select query , homecoming function. above simplified.

delete message m using ( select * ... ) s m.id = s.id returning s.*

sql postgresql plpgsql

c++11 - std::bind no viable conversion -



c++11 - std::bind no viable conversion -

i created pathfind algorithm can set heuristic method. using a

function<int (point2i origin, point2i destiny)> heuristicfunc;

as function pointer , want initialize default heristic.

so:

pathfind.h

class pathfind{ private: function<int (point2i origin, point2i destiny)> heuristicfunc; int hmethod(point2i origin, point2i destiny); public: pathfind(); }

pathfind.cpp

pathfind::pathfind(){ //1st seek this->heuristicfunc=&pathfind::hmethod; //2nd seek this->heuristicfunc=std::bind(&pathfind::hmethod, this); }

but returns same error:

/applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/include/c++/v1/functional:1472:15: candidate function not viable: no known conversion 'int (core::pathfind::*)(point2i, point2i)' 'const std::__1::function, sf::point2)>' 1st argument

why tries convert int(core::pathfind::*) ?

thanks.

using namespace std::placeholders; heuristicfunc = std::bind(&pathfind::hmethod, this, _1, _2);

every argument don't supply has indicated via placeholder.

c++11 functor

wix - Reference a heat generated wxs file from a merge module -



wix - Reference a heat generated wxs file from a merge module -

i want create trivial merge module contains files of directory called "build" , installs them programme files folder. utilize heat generate wxs file these files, , want separated wxs file edit manually merge module. how reference heat generated file other merge module wxs file?

i generate heat wxs file this:

heat dir build -cg heatcomponent -gg -var var.buildfolder -dr programfilesfolder -srd -out heatcomponent.wxs

i know how create msi file of this:

<wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <product name='product' id='9f6edf70-539a-11e4-916c-0800200c9a66' upgradecode='bb651370-539a-11e4-916c-0800200c9a66' language='1033' codepage='1252' version='1.0.0' manufacturer='test'> <package id='*' description="a product" installerversion='301' languages='1033' compressed='yes' summarycodepage='1252' platform='x64'/> <media id="1" cabinet="product.cab" embedcab="yes" /> <directory id='targetdir' name='sourcedir'> <directory id='programfilesfolder'/> </directory> <feature id="files" title="main feature" level="1"> <componentgroupref id="heatcomponent"/> </feature> </product> </wix>

but how do reference componentgroup when want output merge module? if alter product element module element complaints feature element. if remove works, not files in msm.

based on heat command posted, seek making module definition (module1.wxs) this:

<?xml version="1.0" encoding="utf-8"?> <wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <module id="mod1" language="0" version="1.0.0"> <package id="your-guid" manufacturer="acme" /> <directory id="targetdir" name="sourcedir"> <directory id="programfilesfolder" /> </directory> <componentgroupref id="heatcomponent"/> </module> </wix>

then can phone call candle so:

candle module1.wxs heatcomponent.wxs -dbuildfolder="folder-containing-files-here"

followed lite so:

light module.wixobj heatcomponent.wixobj -o module1.msm

wix heat merge-module

Trouble with calling methods in c# -



Trouble with calling methods in c# -

i working on intro level c# calss , having incredibly hard time figuring out methods. book not seem clear in instances. current assignment trying create programme calculates cost of hospital stay. need have 3 different methods program. sense have methods @ to the lowest degree created correctly unsure how create programme output things methods during button click event. here have far(i have tried 1000000 different things in calcbtn_click method , firmly confused).

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.threading.tasks; using system.windows.forms; namespace windowsformsapplication6 { public partial class form1 : form { public form1() { initializecomponent(); } private int calcstaycharges() { int lengthofstay; lengthofstay = int.parse(daystayed.text); int totalstaycharges = (350 * lengthofstay); homecoming totalstaycharges; } private double calcmisccharges() { double medcharges; medcharges = double.parse(medcharge.text); double surgcharges; surgcharges = double.parse(surgicalcharge.text); double labfees; labfees = double.parse(labfee.text); double rehabcharges; rehabcharges = double.parse(rehabcharge.text); double misccharge = (medcharges + surgcharges + labfees + rehabcharges); homecoming misccharge; } public double calctotalcharges() { double misccharges = calcmisccharges(); int staycharges = calcstaycharges(); double totalcharges = misccharges + staycharges; homecoming totalcharges; } private void calcbtn_click(object sender, eventargs e) { messagebox.show(calctotalcharges()); } } }

somewhere in code have assign value returned method variable , show/display variable. example:

int staycharcges = calcstaycharges();

let's in textbox user filled in '3'. staycharges '1050'. can show in label or display through messagebox:

resultlabel.text = string.format("charge: {0}", staycharges); //or resultlabel.tekst = staycharges.tostring() //only number //with messagebox messagebox.show(string.format("charge: {0}", staycharge);

c# methods return

Override joomla admin side error reporting via included PHP file -



Override joomla admin side error reporting via included PHP file -

i'm trying implement (quite rough indeed) debug.php file within of joomla index.php file, right @ start of file. since file calls other extension on server , in browser, i'm forced place file right @ top of file, before core joomla statement initiate application, due various conflicts.

in debug.php file there couple lines activate error reporting this:

// study php errors ini_set('display_errors', 'on'); ini_set('error_reporting', e_all);

since include statement before joomla code, when application init called, administration error study set to:none override called settings. i'd maintain error reporting on admin side set none avoid problem on live site, since debug.php file included simple check if server local environment.

how can implement functionality this? i'm using joomla 3 installation

php joomla error-handling joomla3.0