Ruby, sanitized your titles in 2 lines.

Yesterday I slept super happy, he had managed to write a role for sanitizer strings , or as they say over there: to create a SLUG (which I have not yet found the exact definition). < >

If you do not know that I speak it comes to making a “

Hello world!, So what? ” In a “ hello-world-as-it ” to the URLs beautiful all that.

He had not been easy because Ruby is wrong with the characters

non-ASCII ‘to’ and the Castilian has many, he had to do a little juggling with the gem Unicode .
In the end my role was as follows:

require
  'unicode'    def  to_slug ( sentence, length =  64  )   Return   if  sentence.  Blank ? 

   =',' wrong [' á é',' í',' or',' ú',' ',' ä ë',' ï',' ö',' ü',' à è',' ' ,' ì',' ò',' ù',' ñ',' ç','º' ,'ª','_']  = [' right to',' and',' i',' or',' or',' ',' to e',' i',' or',' or',' to',' e ' ,' i',' or',' or',' n',' s',' or ' ,  'to','-'] 

   [ sentence sentence = 0 .. length - 1 ]    sentence = Unicode.  downcase ( sentence ) 

    for  i  in   0 .. wrong . size - 1   sentence.  gsub !( wrong [ i ], right [ i ] )   End  

   sentence.  gsub !( /[^ to - z0  -9 -]/ , '-' )  # Numbers, not letters of   sentence.  gsub !( /-{ 2 ,}/, '-'  )   # 2 or more '-' becoming together 1'-'  sentence.  gsub !( /^-|-$/, '' )  unless  sentence .  size  ==  1   # '-' at begging or end at     sentence   end 

I was super proud that I wake up in the morning and by changing the question to Google I find a … ‘inombrable’ I do this:

require
  'unicode'    def  to_slug  str = Unicode.  normalize_KD ( self ). gsub (/[^ \ x00  -  \ x7F ]/ n ,'')  str = str.  gsub (/ \ W  / , '-'). gsub ( /^- /,''). Gsub (/- $/, ''). downcase    end 

Exactly (almost) what I had but 2 line.

That’s

¡ Ruby !


In the end I made some changes and got the good from one to another and I’ve added support for stopwords:

Stopwords =
[
    'of',' to',' that',' not',' has',' in', 'to' ,     'by',' him',' the',' what',' the',' the', 'the' ,     'a',' a'   ] 

  def  to_slug ( length =  64 , drop_stopwords =  false  )     return  “”  if   self . length  ==  0  

   str = Unicode.  normalize_KD ( self ). gsub (/[^ \ x00  -  \ x7F ]/ n ,). downcase  

    # Stopwords      if  drop_stopwords      Stopwords.  Each   of  | stopword |        str.  gsub !( / \ s  # stopword) (\ s | ^ # stopword) (\ s /, ”)        end      end  

   str = str.  gsub (/[^ A - Za - z0  -9 ]< >/, ‘-’). Gsub (/^- /,) . gsub (/- $/,). downcase     str = str [ 0 .. length - 1 ]   end  

On his post to be recommended to complete the list of stopwords with whom you want.

As the ranks of a filter using a DataTable RowFilter (VB.Net)

More than once I have come across a form in which sampling data with a DataGridView, but the data show too many, then it is good to add a filter to minimize the number of records displayed.

To do this there are 2 options, the slower it would be a burden on data from the base by applying filters and faster as it operates in memory is to filter the data that are already showing on screen. To do this, in this example will use a DataTable with data from students who dynamic filters.

To begin with this example will need a Form that has a CheckBox to indicate whether to apply the filter or not, a ComboBox to select the field to filter, for entering the TextBox a value of the filter and a DataGrid to display data.

The first thing we do is fill the ComboBox with the name of the columns of our DataTable:

</p> <br /><br /> Private <div class="wp_syntax"><div class="code"><pre class="vbnet vbnet" ><span > </span> <span > Sub </span> LlenarComboColumnas <span >(</span><span >)</span> <br /> <span > If </span> TodosAlumnos <span > IsNot </span> <span > Nothing </span> <span > Then </span> <span > 'TodosAlumnos is the DataTable </span> <br /> <span > For </span> <span > Each </span> c <span > As </span> DataColumn In TodosAlumnos. <span > Columns </span> <br /> <span > I </span>.<span > cmbCampo </span>.<span > Items </span>.<span > Add </span><span >(</span> c. <span > ColumnName </span><span >)</span> <br /> <span > Next </span> <br /> <span > End </span> <span > If </span> <br /> <span > End </span> <span > Sub </span></pre></div></div> <br /><br /> <p>

Then add a method that will handle 3 events: CheckBox.CheckedChanged, ComboBox.SelectedIndexChanged and TextBox.TextChanged. In the latter method was chosen to implement the filter or show all the records again:

</p> <br /><br /> Private <div class="wp_syntax"><div class="code"><pre class="vbnet vbnet" ><span > </span> <span > Sub </span> AplicarFiltro <span >(</span><span > ByVal </span> sender <span > As </span> System. <span > Object </span>, <span > ByVal </span> and <span > As </span> System. <span > EventArgs </span><span >)</span> <span > Handles </span> chkFiltro. <span > CheckedChanged </span>, cmbCampo. <span > SelectedIndexChanged </span>, txtValor. <span > TextChanged </span> <br /> cmbCampo. <span > Enabled </span> <span >=</span> chkFiltro. <span > Checked </span> <span > 'Enable or Disable the ComboBox and TextBox </span> <br /> TxtValor. <span > Enabled </span> <span >=</span> chkFiltro. <span > Checked </span> <br /> <br /> <span > If </span> chkFiltro. <span > Checked </span> <span > Then </span> <br /> Filter <span >(</span><span >)</span> <br /> <span > Else </span> <br /> <span > I </span>.<span > cmbCampo </span>.<span > SelectedIndex </span> <span >=</span> 0 <span > 'Reset the filter </span> <br /> <span > I </span>.<span > txtValor </span>.<span > Text </span> <span >=</span> <span > String </span>.<span > Empty </span> <br /> AlumnosFiltrados <span >=</span> TodosAlumnos. <span > Copy </span><span >(</span><span >)</span> <span > 'Show all the data again </span> <br /> <span > I </span>.<span > DataGridView1 </span>.<span > DataSource </span> <span >=</span> AlumnosFiltrados. <span > DefaultView </span> <br /> <span > End </span> <span > If </span> <br /> <span > End </span> <span > Sub </span></pre></div></div> <br /><br /> <p>

Now we subtract filter, which will in this case, as the example is simple , will check if the data type for the selected column is String use as a condition LIKE and add a wildcard (*) at the end of the value, if change is Integer = use and check the numeric value is entered.

</p> <br /><br /> Private <div class="wp_syntax"><div class="code"><pre class="vbnet vbnet" ><span > </span> <span > Sub </span> Filter <span >(</span><span >)</span> <br /> <span > Try </span> <br /> AlumnosFiltrados <span >=</span> TodosAlumnos. <span > Copy </span><span >(</span><span >)</span> <br /> <br /> <span > If </span> chkFiltro. <span > Checked </span> <span > AndAlso </span> <span > I </span>.<span > cmbCampo </span>.<span > SelectedIndex </span> ><span >=</span> 0 <span > AndAlso </span> <span > Not < > </span> String <span >.</span> IsNullOrEmpty <span ></span>(<span ></span> I <span >.</span> txtValor <span >.</span> Text <span ></span>)<span > </span> Then <span > <br /> </span> Dim <span > column </span> As <span > </span> String <span > </span>=<span > </span> I <span >.</span> cmbCampo <span >.</span> SelectedItem <span >.</span> ToString <span ></span>(<span >< >) </span> <br /> <span > Dim </span> condition <span > As </span> <span > String </span> <span >=</span> <span >"="</span> <br /> <span > Dim </span> value <span > As </span> <span > String </span> <span >=</span> txtValor. <span > Text </span> <br /> <span > 'If you do not get all the data does not apply the filter </span> <br /> <span > If </span> AlumnosFiltrados. <span > Columns </span><span >(</span> column <span >)</span>.<span > DataType </span> <span > Is </span> <span > gettype </span><span >(</span><span > String </span> < >) <span > </span> Then <span > <br /> </span>=<span > Condition </span> "LIKE" <span > <br /> </span>=<span > value </span> <span >.</span> Format String <span ></span>(<span ></span>"'{ 0 }*'"<span >, value </span>)<span > </span> 'Wildcard at the end to get the values that begin with 'value' <span > <br /> </span> ElseIf <span > AlumnosFiltrados. </span> Columns <span ></span>(<span > column </span>)<span >.</span> DataType <span > </span> Is <span > </span> gettype <span ></span>(<span ></span> Integer <span > < >) </span> <span > Then </span> <br /> <span > If </span> <span > Not </span> <span > IsNumeric </span><span >(</span> value <span >)</span> <span > Then </span> <span > 'Check that is numerically </span> <br /> <span > Throw </span> <span > New </span> ArgumentException <span >(</span><span >" The value entered is not correct. You must enter a numeric value ."</span><span >)</span> <br /> <span > End </span> <span > If </span> <br /> <span > End </span> <span > If </span> <br /> <br /> <span > I </span>.<span > AlumnosFiltrados </span>.<span > DefaultView </span>.<span > RowFilter </span> <span >=</span> <span > </span>.<span > Format String </span><span >(</span><span >"{ 0) (1) (2 }"</span>, column, condition, value <span >)</span> <br /> <span > End </span> <span > If </span> <br /> <br /> <span > I </span>.<span > DataGridView1 </span>.<span > DataSource </span> <span >=</span> <span > I </span>.<span > AlumnosFiltrados </span>.<span > DefaultView </span> <span > 'show the filtered data </span> <br /> <span > Catch </span> ex <span > As </span> Exception <br /> MostrarExcepcion <span >(</span> former <span >)</span> <br /> <span > End </span> <span > Try </span> <br /> <span > End </span> <span > Sub </span><span ></span><span > <br /><br /> </span></pre></div> <br /> </div> To test this example download the source code (VS2008). <p> <br />

Also, you may be interested:

How to filter a list of items with LINQ and view the properties for Reflection (VB.Net)

Extension methods in VB.NET (Extension Methods)

  • Applying for calculating the amount of banknotes from the amount in VB.Net
  • Capturing an image of the active window with VB.Net
  • Sort a list of Lambda expressions (multiple criteria) VB.Net

Factor in C – Recursive Function vs. iterative function

Continuing with the theme resources now going to see an example in C which is another of the classics to learn recursive algorithms , the calculating the factorial of a number .

The factorial of a number n, is defined as the product of all the natural numbers ranging from 1 / n, so the factor of 3 is 1 x 2 x 3 = 6. By definition also the factor of 0 is 1.

Let’s look at the above examples, and then the iteratively depending for the calculation of the C-factorial.

  • 3! = 3 x 2 x 1
  • n! X = n (n-1) x (n-2) … x 1

</p> <br /><br /> <div class="wp_syntax"><div class="code"><pre class="cpp cpp" ><span > int </span> factorial <span >(</span><span > int </span> n <span >)</span> <span >{</span> <br /> <span > Int </span> i; <br /> <span > Int </span> fact <span >=</span> <span > 1 </span>; <br /> <span > for </span><span >(</span> i <span >=</span> <span > 1 </span> i <span > </span> n; i <span > </span><span >)</span> <span >{</span> <br /> Fact <span >=</span> fact <span >*</span> i; <br /> <span >}</span> <br /> <span > Return </span> fact; <br /> <span >}</span></pre></div></div> <br /><br /> <p>

Now if we look a little more we can see that n! X = n (n-1)! (for n> 0), from which emerges recursion, now let’s see an example and then the function recursively .

  • 4! = 4 x 3 x 2 x 1
  • 4! = 4 x 3!
  • 3! = 3 x 2 x 1
  • 3! = 3 x 2!
  • 2! 2 x 1 =

</p> <br /><br /> <div class="wp_syntax"><div class="code"><pre class="cpp cpp" ><span > int </span> factorial <span >(</span><span > int </span> n <span >)</span> <span >{</span> <br /> <span > If </span><span >(</span> n <span >==</span> <span > 0 </span><span >)</span> <span >{</span> <br /> <span > Return </span> <span > 1 </span>; <br /> <span >}</span> <br /> <span > Else </span> <br /> <span >{</span> <br /> <span > return </span> n <span >*</span> factorial <span >(</span> n <span >-</span><span > 1 </span><span >)</span>; <br /> <span >}</span> <br /> <span >}</span></pre></div></div> <br /><br /> <p>


Also, you may be interested:

  • Convert a whole base 10 Binary in Java (Recursive)
  • Court of Control – Algorithm and Example in C #
  • Extension methods in VB.NET (Extension Methods)
  • Learn to write recursive functions
  • Method of management of the bubble (bubble sort) Python

Outreach methods in VB.NET (Extension Methods)

The methods extension , extension methods English, is one of the innovations of the last version. Net Framework. As its name suggests, these methods allow extend the functionality of a class without having the source code with it.

In VB.NET you use a module to write the methods extension , and this is precisely the cause of many negative criticisms regarding the use of these methods.

Inside the module will need to define the methods and include the signature attribute that is what will define our approach as a method of extension.

Then you need to have at least one parameter in the signature, we will indicate the class that this method will extend, for example, do a method to extend the class String:

</p> <br /><br /> <div class="wp_syntax"><div class="code"><pre class="vbnet vbnet" ><span >(</span><span >)</span>> _ <br /> <span > Public </span> <span > Function </span> ReemplazoArroba <span >(</span><span > ByVal </span> Chain <span > As </span> <span > String </span><span >)</span> <span > As </span> <span > String </span> <br /> <span > Return </span> String. <span > Replace </span><span >(</span><span >"@"</span>, <span > "(a )"</span><span >)</span> <br /> <span > End </span> <span > Function </span></pre></div></div> <br /><br /> <p>

Then we can call our method as an instance method:

</p> <br /><br /> <div class="wp_syntax"><div class="code"><pre class="vbnet vbnet" ><span > I </span>.<span > TextBox1 </span>.<span > Text </span> <span >=</span> <span > I </span>.<span > TextBox2 </span>.<span > Text </span>.<span > ReemplazoArroba < ></span>(<span ></span>)<span ></span></pre></div> <br /><br /> </div><p>

In signing the method is the parameter that defines the class that stretches, but when it comes to call it, this parameter is not used, now let our method of outreach to accept a parameter to be used for replacing the character @ .

 <br /><br /> </p><div class="wp_syntax"><div class="code"><pre class="vbnet vbnet" >(<span ></span>)<span >> _ <br /> </span> Public <span > </span> Function <span > ReemplazoArroba </span>(<span ></span> ByVal <span > Chain </span> As <span > </span> String <span > Replacement </span> as <span > </span> String <span ></span>)<span > < > As </span> <span > String </span> <br /> <span > Return </span> String. <span > Replace </span><span >(</span><span >"@"</span>, Replacement <span >)</span> <br /> <span > End </span> <span > Function </span><span ></span></pre> <br /><br /> </div></div><p> <br />

Now if, when we will have to call to pass the parameter Replacement:

</p><div class="wp_syntax"><div class="code"> I <pre class="vbnet vbnet" >.<span > TextBox1 </span>.<span > Text </span> <span >=</span> <span > I </span>.<span > TextBox2 </span>.<span > Text </span>.<span > ReemplazoArroba < ></span>(<span ></span>"[ arroba ]"<span ></span>)<span > </span><span ></span> <br /><br /> </pre></div></div> <br /> <p> In the same way and in the same module can implement methods of outreach for several classes, also could be implemented in an existing module of our project, but I prefer to do so by prolixity in an aside.

The following method extends the class

System.Windows.Forms.Control.ControlCollection ‘to’ and adds a method that can be really useful, is a method that seeks to recursively all kinds TextBox controls and erased its contents. < >

(</p><div class="wp_syntax">)<div class="code">> _ <br /> <pre class="vbnet vbnet" > Public <span > </span> Sub <span > EmptyAllTextBoxes </span>(<span ></span> ByVal <span > Controls </span> As <span > Windows. </span> Forms <span >.</span> Control <span >.</span> ControlCollection <span ></span>)< > <br /> <span > For </span> <span > Each </span> c <span > As </span> Controls In Control <br /> <span > If </span> v <span > Controls </span> <span > IsNot </span> <span > Nothing </span> <span > AndAlso </span> v <span > Controls </span>.<span > Count </span>> 0 <span > Then </span> <br /> EmptyAllTextBoxes <span >(</span> c. <span > Controls </span><span >)</span> <span > 'Call recursive </span> <br /> <span > ElseIf </span> v <span > gettype </span><span >(</span><span >)</span>.<span > Equals </span><span >(</span><span > gettype </span><span >(</span> TextBox <span >)</span>< >) <span > </span> Then <span > <br /> </span> CType <span ></span>(<span > c, TextBox </span>)<span >.</span> Text <span > </span>=<span > </span> String <span >.</span> Empty <span > <br /> </span> End <span > </span> If <span > <br /> </span> Next <span > <br /> </span> End <span > </span> Sub <span ></span><span ></span> <br /><br /> <span ></span><span > <br /> </span> You can download a solution </pre> VS2008 </div> with examples of outreach methods to test and modify the code. </div> <br /> <p> Also, you may be interested:

Convert a whole base 10 Binary in Java (Recursive)
How to filter the rows in a DataTable using a RowFilter (VB.Net)

S Factor – recursive function vs. iterative function

    Learn to write recursive functions
  • How to filter a list of items with LINQ and view the properties for Reflection (VB.Net)

Objects in POO

The beauty of the objects that can be used even if you do not know how they work inside. As we have said before, the objects are “as black boxes of functionality.” So what does that mean exactly ?

A black box is a term that engineering works like this. First, drop something into the black box. Then, wait while it is up to us “magically transformed” within it. Finally, we received a new result in the same black box The beauty is that it’s all you need to know is how to return a certain entry adadoa not need to understand the magic inside.

* Well, that means anyone, but the object itself needs to know anything about their properties and methods defined and implemented .

* Are the list of items stored in a matrix or a vector? How is the classification, with a fast or a kind of bubble guy? How is a marked selection and how to handle multiple selections ?

* Encapsulation means that the answers to all these questions are private, known only by the object itself .

* What is the benefit this?

* Well, the advantage is that if you want to use a Select box, it is not necessary to address all the complex code that takes care of all the functionality of a select box. Instead, I just put the self-contained, select the object of my application and use .

* This is an incredibly useful concept because it means that it is much easier to understand and change the code because it only need to deal with small pieces of code in a given time. As a developer, there’s no need to address the complexities of selecting the box functionality, just use the thing !

* It is also a good metaphor for the real world, which can be thought of as being composed of encapsulated objects.

* Consider the computer you’re using to read this. Do you know how the CPU? Most likely you do not. But that’s great. It operates independently. And the fact that you do not have to spend time learning of electrical engineering means you are free to spend his time building things “through” the CPU.

The 7 wonders in the Programacion

1. FORTRAN

You are probably not many agree that FORTRAN is on the list, but this is one of the first programming languages and that is something very important and sufficient reason for belonging to this list.

< > 2. COBOL

“Common Business-Oriented Language, Language Common Business Oriented” Many people think that COBOL is no longer in use but the reality is that still being used for applications requiring porcesamiento batch, we might be surprised if we saw what assets is that even today this language.

If we add to this ancient language (1960), we conclude that there must be on this list.

3. C

C is a programming language created in 1969, is a language of “medium level” but with many features of low level.

There are structures typical of high-level languages, but his instead, offers language constructs that allow an a very low level.

Learning is a basic C C while learning these basic concepts of learning languages such as Java or C #, in addition is not only easier but that they behave Much of its syntax.

4. PERL

Perlno may now be the most popular languages and even that is not attractive to the vast majority of developers, but we must remember that a language such as PHP began as a Perl script that later was released as ” language. “

5. HTML

HTML is not a programming language but a language Marked but should be on this list because it is the standard format of the websites, this has become one of the most popular formats and easy to learn.

6. JAVA

JAVA takes much of its syntax from C and C, but it deserves to be on the list since the java applications are the most used in mobile phones. Java is used mainly for games but there are many other interesting uses.

7. PHP

PHP uses a blend of interpretation and compilation to try to give developers the best mix between performance and flexibility.

PHP compile your code for a set of instructions (called opcodes), provided that these are accessed. These instructions are then executed them one by one until the script ends. This is different than the conventional manner of compilation of languages like C, where the code is compiled to executable code that is then executed. Php is recompiled every time it is requested a script.

An important advantage of interpreting the code is that all the memory used by your code is handled by PHP, and the language automatically empty the memory when the script ends. This means that you do not have to worry about connections to the database because PHP will do it for you.

It is one of the most popular programming languages, high fluidity and speed of their scripts will augur a promising future.