How to remove files using Python (File Remover program included)

1. Problem Description:

After doing some recovery from hard drive the software has created thousand of files which I didn’t needed.

Around 200k txt files . Removing that huge number of files using Windows is very painful because the Windows Explorer crashed. Bill Gates can’t handle it!!!

So I have write some basic script to do it for me:

2. Program (use it at your own risk )

Program goes through  all files in specifies directory and remove specific file types eg: .txt – text file.

You can run this program from Python Gui

import os

indir=”H:\\marzena_zdjecia”

def file_remove(extension,indir):
counter = 0
for root, dirs, filenames in os.walk(indir):
#print(root)
#print(dirs)
for f in filenames:
full_path = root + “\\” + f
if f[-3:] == extension:
#print(full_path)
os.remove(full_path)
counter = counter + 1
print(“Removing ” + full_path)
print(“Removing type: ” + extension +” Number of files removed: “+ str(counter))

file_remove(‘txt’,indir)
file_remove(‘sys’,indir)
file_remove(‘swc’,indir)
file_remove(‘html’,indir)
file_remove(‘xml’,indir)
file_remove(‘chm’,indir)
file_remove(‘rtf’,indir)
file_remove(‘dll’,indir)
file_remove(‘cab’,indir)
file_remove(‘lnk’,indir)

RoR, Sinatra, Padrino and Others: The Power of Ruby Frameworks

RoR, Sinatra,

Padrino and Others: The Power of Ruby Frameworks

This article is an introduction to the power of ruby frameworks. It’s not always easy to pick the right framework for the right work, and in case of ruby there are many frameworks to choose from a good overview should help you to make the right decision.

Some of them are simple and others are complicated. Which one should I choose for a simple web application? I hope you will be able to answer this question yourself at the end.

Getting started

Ruby is a powerful language. It has been there for a while; even so many people still don’t realize how useful and easy it can be. I’ve seen people in the development business switching to Ruby and it’s frameworks after programming for many years in different languages and I think there’s a reason for that. The creator of

Ruby, Yukihiro “Matz” Matsumoto, explained the heart of his language in one sentence:

“Ruby is simple in appearance, but is very complex inside, just like our human body”.

Java or C++ languages are complex to learn and write. You need to fight with their syntax instead using your time to resolve problems. That’s why I recommend having a look at Ruby and trying it! There’s no better way than getting your hands dirty in the code.

Have a good read and pick up the framework of your choice.

Let’s start this article with a short list of Ruby frameworks before we dive deeper into them. Discover and find them yourself on the web:

• Ruby On Rails – http://rubyonrails.org/

• Sinatra – http://www.sinatrarb.com/

• Pardino – http://www.padrinorb.com/

• Cuba – http://cuba.is/

• Cramp – http://cramp.in/

• Merb – http://www.merbivore.com/index.html

And others: Camping, Ramaze, Vintage, Halcyon, Nitro/Og, Wuby, Ruby Waf, Webby.

Prepare yourself for the battle!

First, you need to install Ruby. The best tool to use is

RVM – Ruby Version Manager. Use Linux or Mac OS as your operative system to avoid problems. Open up your terminal and install RVM first.

ami@os ~ $ \curl -L https://get.rvm.io |

bash -s stable –ruby

If installation and configuration were successful, RVM should now load whenever you open a new shell. This can be tested by executing the following command, which should output rvm is a function as shown below.

ami@os ~$ type rvm | head -n 1

rvm is a function

Finally, see if there are any dependency requirements for your operating system by running:

ami@os ~$ rvm requirements

Make sure that everything is installed before proceeding further.

Then install Ruby. The installation process is easy, you need to check which Ruby versions are available and install the latest stable one for best security and performance. You don’t need to specify its number: type in rvm install ruby-1.9.3 and the latest stable version will be installed. If the latest version isn’t available as a package for your distribution, Ruby will be installed from source as shown Listing 1.

ThE POWER OF RuBy FRAMEWORkS

Installation of Ruby – 1.9.3-p374- #complete

Use the newly installed Ruby:

ami@os ~ $ rvm use 1.9.3

Using /home/ami/.rvm/gems/ruby-1.9.3-p374

Check if it works correctly by:

ami@os ~$ ruby -v

ruby 1.9.3p374 (2013-01-15 revision 38858) [i686-linux]

ami@os ~ $ which ruby

/home/ami/.rvm/rubies/ruby-1.9.3-p374/bin/ruby

Optionally, you can set a version of Ruby to use as the default for new shells. Note that this overrides the system ruby:

ami@os ~ $ rvm use 1.9.3 –default

Using /home/ami/.rvm/gems/ruby-1.9.3-p374

Once you got your Ruby installed, you can proceed with framework installation.

Ruby on Rails

To can install Rails, type the following command:

ami@os ~$ gem install rails

The three largest benefits you can expect with Ruby on Rails are:

Quicker launch Sites that would traditionally take 12 weeks to build can commonly be launched inside of 6 weeks with

Ruby on Rails. This timesaving results from several factors: a leaner code-base (fewer lines of redundant code), a modular design (re-using existing components rather than building everything from scratch), and the availability of existing plugins (again, reducing the need to build features from scratch).

Easier changes After the site launch, future modifications to your site (e.g., adding new features, making changes to the data model) can be applied quicker because of the reasons noted above.

Introduction to Ruby/RoR

More cost-effective

Because of the speed with which Rails sites can be built and modified, you spend less money to create and maintain the website – without compromising its quality, performance, or scalability.

RoR has a few disadvantages as well:

• It’s good for small applications due to its being a heavy framework. It contains a lot of features you will never use.

• Static website. You can create a static website in Ruby on Rails but it’s not worth it. Make your life simpler and use Sinatra for this kind of job.

• Blog oriented website. Why reinvent the wheel? WordPress is the right tool to use. If you want to learn more about Ruby or Rails basic concepts, please refer the following links:

http://guides.rubyonrails.org/

http://www.rubyonrailstutorials.com/

Listing 1. Installing Ruby

ami@os ~ $ rvm list known

# MRI Rubies

[ruby-]1.8.6[-p420]

[ruby-]1.8.7[-p371]

[ruby-]1.9.1[-p431]

[ruby-]1.9.2[-p320]

[ruby-]1.9.3-p125

[ruby-]1.9.3-p194

[ruby-]1.9.3-p286

[ruby-]1.9.3-p327

[ruby-]1.9.3-p362

[ruby-]1.9.3[-p374]

[ruby-]1.9.3-head

[ruby-]2.0.0-rc1

ruby-head

….

ami@os ~ $ rvm install 1.9.3

Searching for binary rubies, this might take some time.

No binary rubies available for: debian/wheezy_sid/i386/ruby-1.9.3-p374.

Continuing with compilation. Please read ‘rvm mount’ to get more information on binary rubies.

Installing Ruby from source to: /home/ami/.rvm/rubies/ruby-1.9.3-p374, this may take a while depending on your

ruby-1.9.3-p374 – #downloading ruby-1.9.3-p374, this may take a while depending on your connection…

ruby-1.9.3-p374 – #extracting ruby-1.9.3-p374 to /home/ami/.rvm/src/ruby-1.9.3-p374

ruby-1.9.3-p374 – #extracted to /home/ami/.rvm/src/ruby-1.9.3-p374

ruby-1.9.3-p374 – #configuring

ruby-1.9.3-p374 – #compiling

ruby-1.9.3-p374 – #installing

http://railstutor.com/

Sinatra

Sinatra is a very slim web framework; it needs way less memory at runtime than Rails. Also, since there’s less code involved, request processing is probably faster.

That’s why it can be a very appropriate framework for a web service “this simple”. Sinatra is great to use especially if you need to run many instances (e.g. high traffic or many long running requests), it can be an important factor to the number of machines you need to run your web service.

Sinatra is not, however, good for coding large websites as you would spend a lot of your time doing things, which are already implemented in Rails, like database connections.

Sinatra can be installed and run very easily: Listing 2.

Now open up your browser and paste the following

link to see the sinatra output.

http://localhost:4567/hi

Padrino

To install Padrino, type the following command:

ami@os ~ $ gem install padrino

The best explanation of why you should use Padrino can be found on their website, its installation is explained above and it’s pretty simple. That’s how its creators describe the Padrino framework:

“Many developers fall in love with the simplicity and expressiveness of Sinatra but quickly come to miss a great deal of functionality provided by other web frame-works such as Rails when building non-trivial applications.

Our team has come to love the philosophy of Sinatra which acts as a thin layer on top of rack allowing middleware to do most of the work and enabling additional

complexity only when required. The goal for this framework is to match the essence of Sinatra and make it suitable for increasingly complex

Listing 2. Sinatra installation

ami@os ~ $ gem install sinatra

Fetching: rack-protection-1.3.2.gem (100%)

Fetching: sinatra-1.3.4.gem (100%)

Successfully installed rack-protection-1.3.2

Successfully installed sinatra-1.3.4

2 gems installed

….

ami@os ~$ touch hi.rb

Once you have created the hi.rb you can put some basic setup on it for sinatra to work.

ami@os ~$ vim hi.rb

<< START OF THE FILE >>

require ‘rubygems’

require ‘sinatra’

get ‘/hi’ do

”Hello Sinatra”

end

<< END OF FILE >>

Once the file is saved. Run the command below

ami@os ~ $ ruby hi.rb

[2013-02-05 22:45:56] INFO WEBrick 1.3.1

[2013-02-05 22:45:56] INFO ruby 1.9.3 (2013-01-15) [i686-linux]

== Sinatra/1.3.4 has taken the stage on 4567 for development with backup from WEBrick

[2013-02-05 22:45:56] INFO WEBrick::HTTPServer#start: pid=30869 port=4567

applications that require the use of forms, mail delivery, localization, helpers, caching, etc. For our team, coding is an art form and Sinatra best enables this concept because of these core principles:

• Clean

• Compact

• Fast

• Creative

• Concise

The Padrino framework is the perfect solution for your small projects as well as for your larger project requirements!”

(source: http://www.padrinorb.com/pages/why)

Cuba

Cuba was originally inspired by Rum, a tiny but powerful mapper for Rack applications. It integrates many templates via Tilt, and testing via Cutest and Capybara.

Introduction to Ruby/RoR

It can be installed by running the following command in your terminal:

ami@os ~$ gem install cuba

Cuba has a few advantages:

• Quick and simple

• Similar to Sinatra in some aspects

• Good for small websites with less complexity

And a few disadvantages:

• Small community

• There exist other better or similar frameworks

Cramp

A different Ruby framework is Cramp, which is de- scribed in the following way:

• Lightweight, minimal and able to handle thousands of open connections simultaneously

• Built in support for HTML5 technologies: WebSock-ets and Server-Sent Events (EventSource)

• Easy Streaming APIs

• Allows Ruby 1.9 + Fibers to prevent asynchronous

callbacks spaghetti

• Seamless Active Record integration

• Rack Middlewares support + Rainbows! and Thin web servers.

Cramp’s advantages are:

• Great for working with large numbers of open connections

• Provides full-duplex bi-direction communication

• High performance

• It’s best for streaming actions of an application; other

actions can be handled with a different framework.

Cramp has a few disadvantages as well:

• Other frameworks perform better

• Small Community

• Lack of guides on the Internet.

Merb

Like Ruby on Rails, Merb is an MVC framework. Unlike Rails, Merb is ORM-agnostic, JavaScript library agnos- tic, and template language agnostic, preferring plug-ins

that add in support for a particular feature rather than trying to produce a monolithic library with everything in the core.

Merb’s also thread-safe and was originally engineered to handle multiple file uploads concurrently.

On the Web

https://www.ruby-toolbox.com/categories/web_app_frameworks – Ruby frameworks popularity statistics

http://rubyonrails.org/ – Ruby on Rails

http://rack.github.com/ – Rack a Ruby Web Server Inter- face

http://cramp.in/ – Real-Time Web Application Framework

http://ruby.railstutorial.org/ – One of the best free tutori- als to learn Ruby on Rails

http://mislav.uniqpath.com/poignant-guide/ – For a bit of fun, a famous cartoon based on Ruby

(Source: http://cramp.in/)

It’s main advantages are as follows:

• Speed

• Simple, well documented core

• Lots of features, flexible and extensible

• Generators

• Test and Specs

• Plugins

• Very good documentation.

Merb has just one disadvantage and it’s the fact that it merges into Rails, so, after all, it’s better to stick with Rails.

Summary

There are many Ruby frameworks available now in the web and we can expect this list to grow in the future. It’s not easy to choose the best framework for your programming work. While some of them are suitable to use for simple websites, other will work for complex web- sites such as Twitter, which is actually based on Ruby on Rails. The best way is to give every framework a try and play with it. Try to make some simple websites and check their documentation. I’d recommend starting from a simple framework first (here Sinatra seems to be a good choice), and then progress to more complicated one. Ruby on Rails is the most popular Ruby framework these days, so there are many jobs available once you know your way around it. Eventually, the choice is yours.

Django DatabaseError: no such column error

This is because you have amended your models and you have not changed your database.

Nothing to worry about!

For your info – > python manage.py syncdb ->  will NOT alter the existing schema in the database.

You need to run the python manage.py sqlall <your_app>

and then change your database based on the info given.

You may want to run python manage.py dbshell to do so

Or you can start using the Django addons calles South.

http://south.readthedocs.org/en/latest/installation.html

-> pip install South

-> Open up your apps -> settings.py

->add ‘South’ to your INSTALLED_APPS

-> run python manage. syncdb

-> then run python manage.py schememigration [yourapp_models] –initial

-> and again python manage.py migrate [yourapp_models]

Enjoy!

Did it resolve your problem?

Let me know post your comments !!

SSD Hosting for 5 dollars a month https://www.digitalocean.com/?refcode=71a52388956e

Error detected while processing function pymode#Option:

rror detected while processing function pymode#Option:
line 8:
E121: Undefined variable: g:pymode_syntax
E121: Undefined variable: g:pymode_options
E121: Undefined variable: g:pymode_doc
E121: Undefined variable: g:pymode_lint
E121: Undefined variable: g:pymode_rope
E121: Undefined variable: g:pymode_run
E121: Undefined variable: g:pymode_breakpoint
E121: Undefined variable: g:pymode_utils_whitespaces
E121: Undefined variable: g:pymode_folding
Error detected while processing /home/honghe/.vim/bundle/python-mode/after/inden
t/python.vim:
line 1:
E121: Undefined variable: g:pymode_indent
E15: Invalid expression: pymode#Default(‘b:pymode_indent’, 1) || !g:pymode_inden
t
Error detected while processing function pymode#Option:
line 8:
E121: Undefined variable: g:pymode_syntax

Resolution:

Install Python 2 as well 🙂 together with Python 3
If you have got Python 3 installed it will gives you these errors.

How to Install Django

Install Setuptools first

Mac OS

> wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py -O – | python

Linux/Unix

Note that you will may need to invoke the command with superuser privileges to install to the system Python.

Alternatively, on Python 2.6 and later, Setuptools may be installed to a user-local path:

> wget https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
> python ez_setup.py –user

Install Pip

wget https://raw.github.com/pypa/pip/master/contrib/get-pip.py

$ python get-pip.py

or

Using Package Managers

On Linux, pip will generally be available for the system install of python using the system package manager, although often the latest version lags behind. Installing python-pip will also install python-setuptools.

On Debian and Ubuntu:

$ sudo apt-get install python-pip

On Fedora:

$ sudo yum install python-pip

Then Install Django: ( You can check the latest version on https://www.djangoproject.com/download/)

pip install Django==1.5.5

Now you are ready to rock!

Well done me! Computer Networks Course completed on Cousera :)

networks

About Coursera?

Coursera is an education company that partners with the top universities and organizations in the world to offer courses online for anyone to take, for free. Our technology enables our partners to teach millions of students rather than hundreds.

We envision a future where everyone has access to a world-class education that has so far been available to a select few. We aim to empower people with education that will improve their lives, the lives of their families, and the communities they live in.

What is course about ?

Timeline

The course has ten weeks of content material, including one optional week on network security, that is spread over twelve calendar weeks. There is a weekly review and homework for each of the nine content weeks, plus a midterm and final exam. It is a lot of material, and a course that you can be proud to have completed!

The timeline we plan to follow for the main activity in weeks 1 through 12 is given below. More detail on the topics for each week is given on the Syllabus page. We aim to allow access to weekly content materials early on Saturday morning to let you to begin going over the material on the weekend before the week starts; see deadlines below for the timing of homeworks and exams. We will send out weekly announcements early Monday mornings, as the course week runs from one Monday to the next.

  1. Introduction, Protocols and Layering
  2. Physical and Direct Link layers
  3. Retransmissions, Multiple access,Switching
  4. Network layer and Internetworking
  5. Routing
  6. Midterm, and breather
  7. Transport layer, Reliability Transport
  8. Congestion Control
  9. Web and Content distribution
  10. Quality of Service and Real-time Apps
  11. Optional: Network Security
  12. Final Exam

Is it worth doing?

Definitely Yes, 12 weeks a few hours of lecture a week and assignments works great. You will actually learn and master these materials.

It would be a great preparation for CCNA or other networking certification.

I am sure you will enjoy it.

Many Thanks. I hope this review of the course will make take it!

You can sign up here

https://www.coursera.org/course/comnetworks

Who will teach you?

David Wetherall

David David Wetherall is a Professor of Computer Science & Engineering at the University of Washington. His research on network systems has been awarded the ACM SIGCOMM Test-of- Time Award and the IEEE Bennett Prize. He is known for pioneering results on programmable networks, de-duplication, Internet mapping, and denial-of-service. Prof. Wetherall has taught computer networks to students for the past decade, and he is a co-author with Tanenbaum of the textbook “Computer Networks”. He has a Ph.D. in computer science from MIT, and is a Fellow of the ACM and the IEEE.

Arvind Krishnamurthy

Arvind Arvind Krishnamurthy is an Associate Professor of Computer Science and Engineering at the University of Washington. His research interests span all aspects of building practical and robust computer systems, including distributed systems, computer networks, and security. His recent work is aimed at understanding and making dramatic improvements to the robustness, security, manageability, and performance of Internet-scale systems.

John Zahorjan

John John Zahorjan is a Professor of Computer Science & Engineering at the University of Washington. His research has spanned aspects of computer systems from performance analysis to operating systems and networking. His research work has won the ACM SIGMETRICS Test-of- Time Award.