BetaCodeShareBeta

by Code Solutions Project

Simple solutions for common problems

Last codes
C#
JoseluCross
void generateButton()
{
    Button button = new Button();
    button.Text = "Button";
    button.Click += new EventHandler(Button_Click);
}

void Button_Click(object sender, EventArgs e){
    //OnClick content
}
Matlab
JoseluCross
function [Y] = gaussRecursivo( A )
%Gauss Recursivo
%   Genera una matriz expandida
%   triangular superior al aplicarse Gauss de manera recursiva
    dim = size(A);
    if dim(1) ~= 1
       for i =2:dim(1)
           if A(1,1) == 0
               disp('Se ha necesita pivotaje parcial');
               mayor=0;
               index=0;
               for j = 1:dim(1)
                   if A(1,j) > mayor
                       index=j;
                       mayor = A(1,j);
                   end
               end
               S = A(1,:);
               T = A(index,:);
               A(index,:) = S;
               A(1,:) = T;
           end
           mul = A(i,1)/A(1,1);
           A(i,:) = A(i,:) - mul*A(1,:);
       end
       B = A(2:dim(1),2:dim(2));
       B = gaussRecursivo(B);
       C = [zeros(dim(1)-1,1),B];
       Y = [A(1,:);C];
    else
       Y=A;
    end
end
PHP
JoseluCross
function makePost($url,$keys){

    $options = array(
        'http' => array(
            "header" => "Content-type: application/x-www-form-urlencoded\r\n",
            "method" => 'POST',
            'content'=> http_build_query($keys)
        )
    );
    $context = stream_context_create($options);
    $response = file_get_contents($url,false,$context);

    return $response;
}
Java
JoseluCross
public String toRTF(String text){
	String middle = text
    middel = middle.replace("á", "\\'e1");
    middel = middel.replace("Á", "\\'c1");
    middel = middel.replace("é", "\\'e9");
    middel = middel.replace("É", "\\'c9");
    middel = middel.replace("í", "\\'ed");
    middel = middel.replace("Í", "\\'cd");
    middel = middel.replace("ó", "\\'f3");
    middel = middel.replace("Ó", "\\'d3");
    middel = middel.replace("ú", "\\'fa");
    middel = middel.replace("Ú", "\\'da");
    middel = middel.replace("ü", "\\'fc");
    middel = middel.replace("Ü", "\\'dc");
    middel = middel.replace("ñ", "\\'f1");
    middel = middel.replace("Ñ", "\\'d1");
    return middel;
}
PHP
JoseluCross
function buildAssets(array $folders,array $assets){
    $buildAssets = array();
    foreach($folder as $folders){
        foreach($value as $asset){
            array_push($buildAsset,$foder."/".$value)
        }
    }
    return $buildAsets;
}
C/C++
MagRag
void fillMatrix(int matrix[DIM][DIM]) {
  int i, j;
  for(i = 0; i < DIM; i++) {
    for(j = 0; j < DIM; j++) {
      if(sopa[i][j] == ZERO) {
	sopa[i][j] = random(CHAR_MIN, CHAR_MAX);
      }
    }
  }
}
PHP
MagRag
public function getBirthdays(){
    $queryBuilder = $em->createQueryBuilder();
    $queryBuilder
        ->select("*")
        ->from("Users")
        ->where("DATE_FORMAT(fecha_nac,'%m-%d') = DATE_FORMAT(NOW(), '%m-%d')");
    return $queryBuilder->execute()->fetchAll();
}
Python
Josemi
from functools import lru_cache
@lru_cache(10000)
def sumandos(n):
    res = []
    for i in range(1,int((n)/2)+1):
        if n-i == 1:
            aux=[tuple([1])]
        elif i*2 == n:
            aux=[tuple([i])]
        else:
            aux = sumandos(n-i)
        for j in aux:
            tp=[i]
            if i > j[0]:
                continue
            res.append(tuple(tp)+j)
        if i*2 != n:
            res.append(tuple([i,n-i]))
    return res
Python
Josemi
def inorden(monticulo,n=0):
    hijo1 = 2*n+1
    hijo2 = 2*n+2
    total=[]
    if hijo1 >= len(monticulo):
        return [monticulo[n]]
    elif hijo2 >= len(monticulo):
        return [monticulo[hijo1],monticulo[n]]
    else:
        total += inorden(hijo1,monticulo)
        total.append(monticulo[n])
        total += inorden(hijo2,monticulo)
        return total
Python
Josemi
def incrementa_contador(contador, base = 2):
    camb = 0
    for i in range(len(contador)-1,-1,-1):
        if contador[i] == base -1:
            contador[i]=0
            camb += 1
        else:
            contador[i] += 1
            camb += 1
            break
    return (contador,camb)
×Oh snap! Something wrong