Now the particular issue that I've run into with this example is implementation of Jade mixin s in this example. One I would indicate that the mixin in Jade is simply a short hand java script function for the Jade scripting system (inspired incidentally by Haml for Node). Unfortunately, the Jade script, Profiles.Jade file includes what should apparently be defined as two empty functions which it appears automatically generate an error, but handled by the index.js through the main body apps routes/index.js script...sort of circuitous silliness in my opinion :) ...umm...book example script appears in some ways to be a mess, but...
Monday, November 26, 2012
Monday, November 19, 2012
Node JS and Express 3 example problem, Child express application called inside a Parent express application
The problem that I've seen though Express with Node JS, is stable implementation examples keeping to framework versions. For example, a Node cookbook seems to provide excellent examples say from Express 2, but unfortunately at the time of writing either owing to changes since then through version or for any other reasons, I've spent time studying and trying to re work examples for basic functionality. I'd give the latest problem example: This would include using a app.use() call on another express app embedded into a main express app. Apparently while mount uri citation works, the uri is structurally not integrated into the main express apps router for some odd reason. I'd indicate that I've been able to use app.use() with uri for mounting functions with resend and request calls implementing by default routing...by the way if you use a console.log(app.routes) call to see the uri as route, it won't show, but will if you alternately use app.get() for the same function.
Why the big fuss over the call of one app to another? Well according to the Node cookbook chapter 6 example, going from sub chapter to the next, implementation of previous application functionality can be done so (in a class/module oriented) way simply copying the contents of one application and embedding it in the parent application. Apparently the very basics of this functionality is handled with a
app.use(uri, require('./myappname/app'));
No problem here at least initially. The problem that seems to manifest, at least in the latest version of Express somewhere in the process of child apps sending and receiving request or sending response. At least in my example case, I used on the child express app, using the following function:
app.use(function(req, res, next){
res.send('hello world');
next();
});
It appears the parent app neither provides request communications to child express apps, or the child express apps aren't communicating to the local host...minding I did set up a listener on the child express app
if (!module.parent) {
app.listen(3000, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
}
Thus getting a response Cannot GET /childappuri/ when the uri localhost:3000/childappuri/ is called
At this point stumped what were occurring here. Set up the basic of examples here again...otherwise, the workaround were embedding much in the main app all of the process (a little more involved). Hoping I could find a working example on the most current express 3 version, but couldn't aside from already provided advice through common forums such as StackOverflow which were general enough, didn't see anything at the moment.
A solution:
Thanks to another posting in StackOverflow. The simplest that I've found is simply exporting the app.
Thus I added after all configurations and routing adds the following in the body of child express app in the app.js file:
module.exports = app;
All references above in the parent app should be used, and make sure that the server instantiation in the child express app is removed while using a listener (hadn't checked to see if this were technically necessary).
Why the big fuss over the call of one app to another? Well according to the Node cookbook chapter 6 example, going from sub chapter to the next, implementation of previous application functionality can be done so (in a class/module oriented) way simply copying the contents of one application and embedding it in the parent application. Apparently the very basics of this functionality is handled with a
app.use(uri, require('./myappname/app'));
No problem here at least initially. The problem that seems to manifest, at least in the latest version of Express somewhere in the process of child apps sending and receiving request or sending response. At least in my example case, I used on the child express app, using the following function:
app.use(function(req, res, next){
res.send('hello world');
next();
});
It appears the parent app neither provides request communications to child express apps, or the child express apps aren't communicating to the local host...minding I did set up a listener on the child express app
if (!module.parent) {
app.listen(3000, function(){
console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});
}
Thus getting a response Cannot GET /childappuri/ when the uri localhost:3000/childappuri/ is called
At this point stumped what were occurring here. Set up the basic of examples here again...otherwise, the workaround were embedding much in the main app all of the process (a little more involved). Hoping I could find a working example on the most current express 3 version, but couldn't aside from already provided advice through common forums such as StackOverflow which were general enough, didn't see anything at the moment.
A solution:
Thanks to another posting in StackOverflow. The simplest that I've found is simply exporting the app.
Thus I added after all configurations and routing adds the following in the body of child express app in the app.js file:
module.exports = app;
All references above in the parent app should be used, and make sure that the server instantiation in the child express app is removed while using a listener (hadn't checked to see if this were technically necessary).
Thursday, November 8, 2012
Node Cookbook, Chapter 6 implementation of sessions, site wide management
Okay reading Node Cookbook. I am having difficulties with an example here, namely, Chapter 6, custom middle ware for site wide management, under initializing and using a session. Here the problem encountered namely begins with the alternate use of the deprecated function dynamic helpers(). In this implementation the book calls for
Okay some additional s here of notable mention.
In the views/login.jade file I had to change the reference from
user
to
locals.user
or notably I received an error that user wasn't defined oddly enough.
Secondly I instantiated the function in the configures portion of the app in the following manner:
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('kooBkooCedoN'));
app.use(express.session());
app.use(require('./login'));
app.use( function (req, res, next) {
console.log('hit func1');
res.locals.user = req.session.user;
next();
});
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
Try moving this app.use() function with res.locals.user assignment just after the app.use(app.router); instantiation and you might as I did have problems with your function being called even though it were technically instantiated, or this is to say, I've found this function has to be called before the app.router instantiation but not before the require('./login') instantiation !!! Obviously the assigning before the require(./login) assignment references res.locals.user before user has technically been assigned in the ./login module, or at least received an undefined assignment error here, and then it appears that app.router assignments causes disregard in express of any app.use() response, request, next functions needed to set res.local.user...so order of instantiation is very important here.
Since I am a noob when working with express here, it is worth noting that that app.get() function that conflict with app.use() functions on response and requests basis neither coupled may with next(); generate un desired results, or at least I've run into these sorts of problems especially as pertaining to GET page routing.
app.locals.use( function (req, res) { res.locals.user = req.session.user; });However this gives rise to error at least in my case, so a slight modification of this alternately is
app.use( function (req, res) { res.locals.user = req.session.user; });which seems to resolve some issue here, but then I get an error in the views>login.jade file referencing user.
Okay some additional s here of notable mention.
In the views/login.jade file I had to change the reference from
user
to
locals.user
or notably I received an error that user wasn't defined oddly enough.
Secondly I instantiated the function in the configures portion of the app in the following manner:
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.use(express.favicon());
app.use(express.logger('dev'));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser('kooBkooCedoN'));
app.use(express.session());
app.use(require('./login'));
app.use( function (req, res, next) {
console.log('hit func1');
res.locals.user = req.session.user;
next();
});
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
Try moving this app.use() function with res.locals.user assignment just after the app.use(app.router); instantiation and you might as I did have problems with your function being called even though it were technically instantiated, or this is to say, I've found this function has to be called before the app.router instantiation but not before the require('./login') instantiation !!! Obviously the assigning before the require(./login) assignment references res.locals.user before user has technically been assigned in the ./login module, or at least received an undefined assignment error here, and then it appears that app.router assignments causes disregard in express of any app.use() response, request, next functions needed to set res.local.user...so order of instantiation is very important here.
Since I am a noob when working with express here, it is worth noting that that app.get() function that conflict with app.use() functions on response and requests basis neither coupled may with next(); generate un desired results, or at least I've run into these sorts of problems especially as pertaining to GET page routing.
Tuesday, November 6, 2012
Electoral outcomes python script
The following python scripts computes a permutation of outcomes for electoral success if Obama holds leaning blue states. I computed a total of 18 distinct electoral outcomes which lead to success, this actually could be reduced a bit, since there maybe set overlap if not including the state of Florida which automatically provides Obama a win if Obama holds every other projected state and leaning states are included. Just run script in Idle then type 'perms' or you could modify script for a list print
mapdict = {'va': 13, 'nh': 4, 'oh': 18, 'wi': 10, 'ia': 6, 'co': 9}
def checkset(pickmap, mappicks):
mpcheck = True
checkcont = 0
for mappick in mappicks:
checkcont = 0
for pick in pickmap:
if pick in mappick:
checkcont += 1
if checkcont == len(mappick):
return True
def checkmap(inmap, score):
mappicks = {}
mappick = []
newscore = score
for state in inmap:
newscore = score
newscore += mapdict[state]
mapcopy = inmap.copy()
del mapcopy[state]
if newscore < 27:
#print(state, len(mapcopy))
returnpicks = checkmap(mapcopy, newscore)
for pick in returnpicks:
#print (state, pick)
if returnpicks[pick] > 26:
cpick = list(pick)
rpick = cpick[0:len(cpick)]
rpick.append(state)
rtuppick = tuple(rpick)
if not checkset(rtuppick, mappicks):
mappicks[rtuppick] = returnpicks[pick]
else:
mappicks[tuple([state])] = newscore
return mappicks
perms = checkmap(mapdict, 0)
mapdict = {'va': 13, 'nh': 4, 'oh': 18, 'wi': 10, 'ia': 6, 'co': 9}
def checkset(pickmap, mappicks):
mpcheck = True
checkcont = 0
for mappick in mappicks:
checkcont = 0
for pick in pickmap:
if pick in mappick:
checkcont += 1
if checkcont == len(mappick):
return True
def checkmap(inmap, score):
mappicks = {}
mappick = []
newscore = score
for state in inmap:
newscore = score
newscore += mapdict[state]
mapcopy = inmap.copy()
del mapcopy[state]
if newscore < 27:
#print(state, len(mapcopy))
returnpicks = checkmap(mapcopy, newscore)
for pick in returnpicks:
#print (state, pick)
if returnpicks[pick] > 26:
cpick = list(pick)
rpick = cpick[0:len(cpick)]
rpick.append(state)
rtuppick = tuple(rpick)
if not checkset(rtuppick, mappicks):
mappicks[rtuppick] = returnpicks[pick]
else:
mappicks[tuple([state])] = newscore
return mappicks
perms = checkmap(mapdict, 0)
Friday, October 26, 2012
Windows 8 Pro upgrade experience.
Fortunately for my Lenovo laptop, upgrade integration went smoothly and nicer then I had expected. I were able to do the upgrade even preserving previous side by side installations and master boot records with an existing Linux distro. The value for the operating system excellent likewise. The Windows 8 user interface may take some time for me to get used to but in fairness the same difficulties could have been much the same for Ubuntu's Unity. Its seems the interface reminds of the integration of a tablet or alternate peripherals culture. Here relative the browser based interfaces, laptop and desktops such users might seem to benefit less from the start menus window 8 integration messaging, email, and peoples apps, for instance, but in comparison it seems even on the Linux side of distribution, umbrella messaging app integration s appears to be a trend. Honestly, in the some many years of staying away from facebook or twitter, I succumbed and signed up for accounts, alongside some others not withstanding Tumblr. I am too poor, of course, to work extensively with peripherals: smartphones, tablets and anything else that could serve to benefit greater here, but for the value I couldn't complain. Aside from the start menu and other Ubnutu"lensing" like aspects offered here, the overall desktop experience isn't so much a stretch from the windows 7 interface. Pulling up applications by the way is a bit different...or at least I determined this indirectly using a pull the start menu > right mouse button > hit all apps combination to do the trick of finding apps not immediately listed in start menu. Likewise if you manage to pull the search tab from the right side bar. Here there is a locus trick with the mouse pointer that I hadn't figured out...if there were more of a tablet or surface like touch elegance found with the mouse pointer, I might be more dazzled by this otherwise. If you were expecting for elation here with the desktop, or laptop that hadn't resembled a tablet, the value I think brings more here relative the upgrade from windows 7 to 8 that seems more so and so for a really new experience. Generally speaking I hadn't lost anything to my recollection in the transfer of data and applications, and there again these days now with ever increasing use of web based applications and online storage filling the role of computing needs, I've found less hassle in moving to a new operating system, and otherwise, mostly I was prepared to lose my Linux distro for the hassle of a new side by side attempted installation, this time windows seemed a little more friendly to the alternate operating system presiding on my laptop.
Lastly, this brings a theory to mind and why some users absolutely disliked the Unity interface and jumped ship from Ubuntu to Mint which retains some of the more traditional and conservative desktop UI. It would seem windows 8 parses between a new design philosophy and the tradition having been the mainstay which were the desktop itself, I actually liked the new windows 8 start interface, the old desktop still reminds that something of previous cultural traditions are hard to die, or at least something of a resistance to the idea that the larger screens would vacate old desktop models completely. The application switcher (pull this by toggling the thumb start link then on the same vertical axis hoover the mouse to the north of this location) might have hinted at possibilities here: forgoing all sorts of potential application screen clutter and thumb tabs that scarcely remain to be understood...okay more likely with the added tab too many in the browser. Honestly I would have been even happier if my windows 8 seemed more then ever like an elegant tablet, however having the mouse peripheral driving the interface in some manner. Maybe a bit much for many users vested in conservative traditions, but then the traditional desktop has been there and if windows 8 looked looked so much like its pre cursor what could one say of the next desktop generation?
Lastly, this brings a theory to mind and why some users absolutely disliked the Unity interface and jumped ship from Ubuntu to Mint which retains some of the more traditional and conservative desktop UI. It would seem windows 8 parses between a new design philosophy and the tradition having been the mainstay which were the desktop itself, I actually liked the new windows 8 start interface, the old desktop still reminds that something of previous cultural traditions are hard to die, or at least something of a resistance to the idea that the larger screens would vacate old desktop models completely. The application switcher (pull this by toggling the thumb start link then on the same vertical axis hoover the mouse to the north of this location) might have hinted at possibilities here: forgoing all sorts of potential application screen clutter and thumb tabs that scarcely remain to be understood...okay more likely with the added tab too many in the browser. Honestly I would have been even happier if my windows 8 seemed more then ever like an elegant tablet, however having the mouse peripheral driving the interface in some manner. Maybe a bit much for many users vested in conservative traditions, but then the traditional desktop has been there and if windows 8 looked looked so much like its pre cursor what could one say of the next desktop generation?
Wednesday, October 24, 2012
Rails 3 problems encountered so far
Working on Rails 3 application with Devise. The problems that I have encountered thus far or opinions concerning Rails from what I have seen in the entry level context:
- Database, Controller, and Views outside pre fabricated structures have posed as increasingly difficult with respect to the database object associations (many to one, one to many). I've for instance managed to easily create controller and views in the path of one to many (e.g., mapping from users any number of posts isn't so hard), but I've had a difficult time mapping views of the many objects in one fell swoop (e.g., mapping all posts from the set of users...sort of has and hasn't worked for me). In other words, digging deeper into customization with Rails hasn't appeared as easy beyond the first glances of generate and scaffold commands.
- Problems with controller to view and route interpretations. I set a route_to view_path link in a given rails html file and the interpreter seems to think the page makes action call to controller method isn't a redirect to another page handling the call to the actual controller action but seems to think it is the page request handling data passing to the actual controller action. Alongside the task handling of user sessions verification in Devise with a customized controller function embedded in say something like a Posts controller, management appears neither so quick and easy on the customization end.
I'd lastly mention, I don't know as a noob that I am such a fan of controller architecture in the view models...one it seems that queries to database objects themselves could be more independent of the views themselves or why each and every page should have some compartmental controller structure that makes routing for database access so difficult when simpler security layers could be embedded into the framework alternately, and data inquiry could be opened up...tempts me to try and construct my own framework relative to something like this, or at least alternately outside of .net there's Django...
Thursday, October 11, 2012
Rails 3 layout customization and gems stuff
Some interesting and possibly useful Rails Gems for website development that I've found thus far:
-Authenticators/ user session login handling: Devise
File Streaming and downloading: see Action Controller Overview
Contributing to this list as I go...
Subscribe to:
Posts (Atom)
Oblivion
Between the fascination of an upcoming pandemic ridden college football season, Taylor Swift, and Kim Kardashian, wildfires, crazier weathe...
-
For starters, as I've seen (pardon my ignorance if I am incorrect), it seems a common way to use path based animated motion for objects...
-
I've looked through a series of web sites on this topic, any number of these ranging in various degrees of technical information, but...
-
Okay so if you read into python scripting examples of moving vertices around in Blender, it seems whether using a bpy.context or bpy.data c...