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)

How to iterate through every file in one directory using Ruby

There are many ways of doing it the one below is my favorite.

We use Dir.glob – function and we iterate through all directories. This might be useful when you need to remove thousand of .txt files after system recover for instance.

Dir.glob(“**/*.txt”) do |my_text_file| # note one extra “*”
puts “working on: #{my_text_file}…”
end

 

Web Penetration Training Just Got better

It’s so good that i just need to recommended it.

Interested in getting a job in security industry? This is the place to start

https://pentesterlab.com/

Learn Web Penetration Testing: The Right Way.

PentesterLab is an easy and great way to learn penetration testing.
PentesterLab provides vulnerable systems that can be used to test and understand vulnerabilities.

Bootcamp

Bootcamp provides a learning path to get into security and especially web penetration testing.

This course is a list of things to read and do, no solutions are provided since it is, in my opinion, the best and only way to learn. If you don’t manage to get one of the items done, just try harder, spend more time googling and find the solution. Finding something by yourself is the best way to learn.

A Collection of best front End frameworks for

This is not a my collection but I have found it being very good 🙂

Full list down here 🙂 with a nice graphical interface.

http://usablica.github.io/front-end-frameworks/compare.html

  • Cascade Framework

  • LESS SASS
  • MIT

  • Cascade Framework Light

  • LESS SASS
  • MIT

  • Twitter Bootstrap

  • LESS SASS
  • Apache v2.0

  • Foundation

  • LESS SASS
  • MIT

  • UIkit

  • LESS SASS
  • MIT

  • 960 Grid System

  • LESS SASS
  • GPL & MIT

  • Skeleton

  • LESS SASS
  • MIT

  • 99lime HTML KickStart

  • LESS SASS
  • MIT

  • Kube

  • LESS SASS
  • Open Source

  • Less Framework

  • LESS SASS
  • Apache v2.0

  • Flaminwork

  • LESS SASS
  • Apache v2.0

  • G5 Framework

  • LESS SASS
  • Open Source

  • Easy Framework

  • LESS SASS
  • CC

  • Blueprint

  • LESS SASS
  • Open Source

  • YAML

  • LESS SASS
  • CC-BY

  • BlueTrip

  • LESS SASS
  • Open Source

  • YUI CSS

  • LESS SASS
  • BSD license

  • Elements

  • LESS SASS
  • Open Source

  • 52framework

  • LESS SASS
  • CC

  • elastiCSS

  • LESS SASS
  • MIT

  • Boilerplate

  • LESS SASS
  • New BSD

  • Emastic

  • LESS SASS
  • Open Source

  • Malo

  • LESS SASS
  • MIT

  • The Golden Grid

  • LESS SASS
  • MIT

  • 1kb grid

  • LESS SASS
  • Open Source

  • Fluid 960 Grid System

  • LESS SASS
  • GPL / MIT

  • Baseline

  • LESS SASS
  • CC

  • Lovely CSS Framework

  • LESS SASS
  • MIT

  • xCSS

  • LESS SASS
  • MIT

  • FEM CSS Framework

  • LESS SASS
  • MIT/GPL

  • Helium

  • LESS SASS
  • Apache v2.0

  • Knacss

  • LESS SASS
  • CC-BY

  • Groundwork CSS

  • LESS SASS
  • Open Source

  • Gumby

  • LESS SASS
  • Open Source

  • Unsemantic

  • LESS SASS
  • MIT/GPL

  • Seelva

  • LESS SASS
  • Apache 2.0

  • Tuktuk

  • LESS SASS
  • MIT

  • Maple

  • LESS SASS
  • MIT

  • Fluidable

  • LESS SASS
  • CCO

  • Ink

  • LESS SASS
  • MIT

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.