Skip to content

Instantly share code, notes, and snippets.

public class Empleado {
public string Nombre { get; set; }
public string ApellidoPaterno { get; set; }
public string ApellidoMaterno { get; set; }
}
public class App {
public static void Main() {
var empleados = new List<Empleado>();
//Se llena la coleccion de empleados, la implementación se deja como ejercicio al lector
@albertein
albertein / gist:744285
Created December 17, 2010 00:32
Using reflection + delegates to dinamically filter IEnumerable<T>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Linq.Expressions;
namespace ConsoleApplication2
{
class Program
{
@albertein
albertein / pixelate.rb
Created June 27, 2011 18:35
CodeBrawl pixelating contest entry
require 'chunky_png'
image = ChunkyPNG::Image.from_file('input.png')
width = image.width
height = image.height
size_factor = 10
pixelated_width = width / size_factor
pixelated_height = height / size_factor
@albertein
albertein / gist:1352164
Created November 9, 2011 17:23
Simple jQuery Ajax example.
<!DOCTYPE html>
<html>
<head>
<title>DEMO</title>
<script src="urlToJQuery"></script>
<script>
$(document).ready(function() {
$("#sumbit-button").click(function(){
var name = $("#name").val();
var age = $("#age").val();
@albertein
albertein / smart_nl2br.php
Created January 26, 2012 16:42
Apply nl2br to a string except for the content of a given string (Useful for <pre> tags)
<?
function smart_nl2br($data, $opening_tag, $closing_tag) {
$results = "";
$closing_tag_length = strlen($closing_tag);
while(($position_start = strpos($data, $opening_tag)) !== false) {
$position_end = strpos($data, $closing_tag);
$previous_data = substr($data, 0, $position_start);
$tag_data = substr($data, $position_start, $position_end - $position_start + $closing_tag_length);
$data = substr($data, $position_end + $closing_tag_length);
$results = $results . nl2br($previous_data) . $tag_data;
def factorial(number)
total = 1
for i in 1..number
total = total * i
end
return total
end
def sum_digits(number)
string = number.to_s
@albertein
albertein / standar_dev.rb
Created February 10, 2012 18:54
Second challenfe for http://apply.embed.ly
# encoding: UTF-8
def standar_deviation(values)
total = 0.0
values.each { |value| total += value }
average = total / values.length
total = 0.0
deviation = values.each { |value|
total += (value - average) ** 2
}
@albertein
albertein / half_text.rb
Created February 10, 2012 19:03
Third challenge for http://apply.embed.ly
def count_words(max_occurrences, unique_words)
unique_words -= 1
total_words = max_occurrences
for i in 2..unique_words
total_words += max_occurrences / i.to_f
end
return total_words
end
def search(max_ocurrences, unique_words)
@albertein
albertein / multi.vb
Created March 23, 2012 04:27
Primer programa de mi hijo
TextWindow.WriteLine("hola")
TextWindow.WriteLine(" hola soy tito ")
TextWindow.WriteLine( "te amo mama " )
TextWindow.Write("8x7=")
TextWindow.WriteLine(8*7)
TextWindow.WriteLine(10+20*53)
TextWindow.WriteLine("3 en ingles es tree")
@albertein
albertein / transtatement.php
Created June 4, 2012 01:18
PDO transactions + prepared statemes
$dbh->beginTransaction();
$statement = $dbh->prepare("INSERT INTO TABLE (field1, field2) VALUES (:v1, :v2)");
$stmt->bindParam(':v1', $value1);
$stmt->bindParam(':v2', $value2);
for ($i = 0; $i < 300; $i++) {
$value1 = 'value';
$value2 = 'another value';
$stmt->execute();
}