Thursday, 3 October 2013

var varName = function funcName() {}

var varName = function funcName() {}

what is the difference between
var a = function() {}
and
var a = function b() {}
The latter, b is undefined?
I'm new to Javascript. Thanks!

Wednesday, 2 October 2013

Adjusting a RegEx to require 2 digits after an optional decimal?

Adjusting a RegEx to require 2 digits after an optional decimal?

I believe I've found the "perfect" Regular Expression to check against for
currency in jQuery Validate, except it seems to allow the user to put a
single lone decimal at the end or a decimal with a single digit after.
Matches: 700. and 3.0
The Regex:
^\$?([1-9]{1}[0-9]{0,2}(\,[0-9]{3})*(\.[0-9]{0,2})?|[1-9]{1}[0-9]{0,}(\.[0-9]{0,2})?|0(\.[0-9]{0,2})?|(\.[0-9]{1,2})?)$
I've been playing with it in http://gskinner.com/RegExr/ but can't seem to
modify it in the right places to fix my decimal issue.
Currently it matches everything I need it to:
700,000
700,000.00
700000

Batch editing of csv files with Python

Batch editing of csv files with Python

I need to edit several csv files. Actually, most of the files are fine as
they are, it's just the last (41st) column that needs to be changed. For
every occurrence of a particular string in that column, I need it to be
replaced by a different string; specifically, every occurrence of 'S-D'
needs to be replaced by 'S'. I've tried to accomplish this using Python,
but I think I need to write the csv files and I'm not quite sure how to do
this:
import os
import csv
path=os.getcwd()
filenames = os.listdir(path)
for filename in filenames:
if filename.endswith('.csv'):
r=csv.reader(open(filename))
for row in r:
if row[40] == "S-D":
row[40] = "S"
Any help? Also, if anyone has a quick , elegant way of doing this with a
shell script, that would probably be very helpful to me as well.

Cocoa programming app with multiple view

Cocoa programming app with multiple view

I'm programming a simple application for Mac OSX, using cocoa framework. I
don't know how sending messages between 2 different view in the same
windows. My app have 2 view : first view that contains 1 form and 1 submit
button, second view that contains a WebView that loads a flash.
The steps to do are :
1) At start do a control and based on the result it shows view1 or view2
2) If view1 is visualized, on the submit action, based on inserted data,
view1 disappears and view2 appears.
I would know how build window and views and how manage this logic. Thanks.

Tuesday, 1 October 2013

the 7 digit even number

the 7 digit even number

Find a number with the following conditions:
i. It is a $7$ digit number.
ii. There is no repetition of digits.
iii. The digit 5 is in the thousands place.
iv. The greatest digit is in the millions place
v. The digit in the hundred thousands place is twice the digit in the
hundreds place.
vi. The digit in the hundreds pace is twice the digit in the ones place.
vii. The digit in the tens place is two less than the digit in the
millions place
vii. The value of the digit in the ten thousands place is zero.

How do I configure Chef Solo to install Nginx on a new Vagrant box?

How do I configure Chef Solo to install Nginx on a new Vagrant box?

I'm new to Chef and the documentation (even the home page of their
website) makes my head spin. I'm not even sure if I'm using it for the
correct purpose.
My intent is to setup a Vagrantfile that tells Chef Solo to automatically
install some software automatically when I spin up a new box. That is one
of Chef Solo's intended uses, am I correct?
I'm not really sure if that qualifies as one of "the hardest
infrastructure challenges on the planet", but whatever.
My first goal is to get Chef Solo to install nginx for me. In my project,
I've cloned the cookbook for nginx:
$ git clone https://github.com/opscode-cookbooks/nginx.git cookbooks/nginx
I edited my Vagrantfile to look like this:
Vagrant.configure("2") do |config|
config.vm.box = "opscode-ubuntu-1204"
config.vm.provision :chef_solo do |chef|
chef.add_recipe "nginx"
end
end
When I ran vagrant up, I got some errors that some cookbooks weren't found
(build-essential, apt, etc), so I cloned them from their appropriate
repos. Now, when I vagrant up, I'm getting this output:
[2013-10-01T20:31:03+00:00] INFO: Processing package[nginx] action install
(nginx::package line 38)
================================================================================
Error executing action `install` on resource 'package[nginx]'
================================================================================
Chef::Exceptions::Exec
----------------------
apt-get -q -y install nginx=1.1.19-1ubuntu0.1 returned 100, expected 0
Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/nginx/recipes/package.rb
38: package node['nginx']['package_name'] do
39: notifies :reload, 'ohai[reload_nginx]', :immediately
40: end
41:
Compiled Resource:
------------------
# Declared in
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/nginx/recipes/package.rb:38:in
`from_file'
package("nginx") do
action :install
retries 0
retry_delay 2
package_name "nginx"
version "1.1.19-1ubuntu0.1"
cookbook_name :nginx
recipe_name "package"
end
[2013-10-01T20:31:08+00:00] INFO: Running queued delayed notifications
before re-raising exception
[2013-10-01T20:31:08+00:00] ERROR: Running exception handlers
[2013-10-01T20:31:08+00:00] ERROR: Exception handlers complete
[2013-10-01T20:31:08+00:00] FATAL: Stacktrace dumped to
/tmp/vagrant-chef-1/chef-stacktrace.out
[2013-10-01T20:31:08+00:00] FATAL: Chef::Exceptions::Exec: package[nginx]
(nginx::package line 38) had an error: Chef::Exceptions::Exec: apt-get -q
-y install nginx=1.1.19-1ubuntu0.1 returned 100, expected 0
Chef never successfully completed! Any errors should be visible in the
output above. Please fix your recipes so that they properly complete.
How can I fix my recipes so that they properly complete?

Array declaration – askubuntu.com

Array declaration – askubuntu.com

How can I declare an array in Ubuntu ? I have tried the code below
Unix=('Zero' 'One' 'Two') #echo -n "area2[0] = " echo ${area2[@]} # Aha,
zero-based indexing (first element of array is [0], not …

Is a game view "stack" really a Stack? – gamedev.stackexchange.com

Is a game view "stack" really a Stack? – gamedev.stackexchange.com

Given the academic definition of a Stack as "A data structure where items
are added in a FILO manner and accessed in such a way that only the top
item may be examined or removed to be modified." Game …