An identifier in Java, C++ and most other programming languages must
begin with a letter and then may be followed by any number of letters or
digits.
It is possible that underscores (_) will also appear, but only in the middle and never two consecutively.
Write a program to read a string and output whether it is a valid or
invalid identifier. Each string will be 10 characters or less in size.
Example 1:
Enter id: UAB_HSPC
Answer: UAB_HSPC is a valid identifier
Example 2:
Enter id: _a_b__2
Answer: _a_b__2 is not a valid identifier
My ruby solution (which is not complete):
print "Identifier: "
identifier = Array.new
def words(identifier)
identifier.each_char.to_a {|word| words}
end
if words(gets).first.match /^[a-zA-Z]+$/i
print "The identifier is valid."
else
print "The identifier is not valid."
end
Coquilles Web & Logo
Wednesday 30 August 2017
Tuesday 13 January 2015
Personal website
Graphical Design: Coquilles web logo
This is my new personal website where I write about writing books, investing and software:
ljnissen.com
Then there's also another website:
coquilles-web-logo.se
Welcome!
Saturday 9 August 2014
Sequential Rake tasks
If you are developing in Rails, chances are that you at some point would like to run Ruby code as Rake tasks. This may be a little bit tricky especially when you have sequential tasks with dependencies.
In this post I will explain how to run multiple rake tasks in sequence:
1./ Create an empty file in lib/tasks
2./ Name the file Something.rake (the .rake suffix is important).
3./ Then fill out your Ruby code within tasks, like so:
In this post I will explain how to run multiple rake tasks in sequence:
1./ Create an empty file in lib/tasks
2./ Name the file Something.rake (the .rake suffix is important).
3./ Then fill out your Ruby code within tasks, like so:
4./ Then run your rake task from the root of your Rails application:
and your rake tasks are performed in sequence.
Learn more about this subject from Ryan Bates at Railscasts or from Łukasz Wróbel.
Saturday 2 August 2014
Copy table from one SQLite database to another
If you are anything like me, you like clear instructions for doing things. This is especially true when it comes to figuring things out on the computer.
Unfortunately, explanations that are easy to follow often lack when it comes to programmers.
The other day I came across a problem where I wanted to move a table in a SQLite-database to another SQLlite-database in my RubyOnRails-learning project.
Now, there are explanations out on the internet, but they require prior knowledge, knowledge that I don't have. So it took a bit of hand wringing before I figured it out.
This is why I thought that I should write a blog post about it where I explain everything in detail.
Copying table from one SQLite database to another:
1./ Open the primary database in the root of your RailsApp:
$ SQLite3 db/primaryDB
You should now have entered SQLite.
SQLite>
2./ Then attach the database that you would like to copy from:
SQLite> ATTACH 'db/secondaryDB' AS SampleDB;
3./ Now you can have a look at what you've achieved so far:
SQLite> .databases;
SEQ NAME FILE
0 Main db/primaryDB
2 SampleDB db/secondaryDB
4./ Here comes the rub:
SQLite> INSERT INTO table_A SELECT * FROM SampleDB.table_B;
Hope this helps!
Friday 2 May 2014
Ny webbsida
Vår nya webbsida är uppe! Gå in på coquilles-web-logo.se för att läsa mer om oss. Där kan du bland annat läsa om vad vi erbjuder och till vilka priser, vad vi kan och mycket annat.
Välkommen!
Friday 18 April 2014
TestFirst Teaching
Graphic Design: Coquilles
Today I wanted to talk about a method to learn code, Test-First Teaching, where the teacher basically give out tests to the students to solve.
One of the best ways to code is Test-Driven Development (TDD) where you set up tests for each new feature of the program before implementing them.
This gives a nice flow to the whole logic of the program and really helps you when designing and executing.
This is method that was pioneered by Alex Chaffee for JAVAscript in the early 2000:s and then further refined and implemented in the Rails framework in 2007.
Around the same time there were several people who thought about expanding the whole concept of TDD in programming to the classroom.
The basic idea is that instead of the teacher giving a lecture in front of the class, he/she instead gives the students small tasks to solve either individually or in pairs.
Surprisingly, the learning was much better and the level of engagement of the students was also much higher than with traditional teaching.
The students report that they enjoy the method much more than traditional teaching and when the students work together in small groups they can easily teach each other the difficult stuff.
Since we here at Coquilles also teach part-time, this is definitely a lesson that we will bring to the classroom and implement in our own teaching.
Read more about TestFirst-Teaching here.
All the best.
/LJ
Friday 11 April 2014
Why you should learn Rails
Graphic Design: Coquilles
If you are interested in development of web applications I suggest learning one of the integrated development tools such as "Django" for Python or "Ruby on Rails" for Ruby.
One of the best ways to learn is simply by doing and I personally find Michael Hartl's Rails tutorial indispensable.
The tutorial is really thoroughly made and I haven't actually found a single glitch anywhere.
It's designed to last about a month and I really urge you to take that time and properly read all the documentation before beginning programming yourself.
It also has some very good exercises that I encourage you to solve.
Another benefit is that Hartl uses test-driven programming throughout the book which actually adds another dimension to the whole narrative in that it turns out exciting to see if your tests pass or fail.
In the tutorial you get to develop a twitter-like web application from scratch. It takes a lot of time, but it's worth it!
If you want to learn more about programming and web development as a hobby, please subscribe to our mailing list! You can do that here.
Best
/LJ
Subscribe to:
Posts (Atom)