BetaCodeShareBeta

by Code Solutions Project

Simple solutions for common problems

Last codes
Python
JoseluCross
import resource
def limit_memory(bytes):
    soft, hard = resource.getrlimit(resource.RLIMIT_AS)
    resource.setrlimit(resource.RLIMIT_AS, (bytes, hard))
Bash
JoseluCross
 python -m ipykernel install --user --name <<>> --display-name "<<Display Name>>"
PHP
Kprkpr
//index.php

<div id="table"></div>

<script>
	setInterval(refreshTable,30000);
		function refreshTable{
			conexion = new XMLHttpRequest();
			// Preparar la funcion de respuesta
			conexion.onreadystatechange = function() {  /* Mostrar */
			if(conexion.readyState == 4 && conexion.status == 200) {
							document.getElementById('table').innerHTML = conexion.responseText;
					}
			}
			// Realizar peticion HTTP
			conexion.open('POST', 'https://example.org/ajax.php');
			conexion.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

			conexion.send("see=statustable");
		}
</script>

//ajax.php
<?php
if ($_POST['statustable']){
    return "<table><tr><td>Hello</td></tr></table>";
}
Java
JoseluCross
public static int getResId(String resName, Class<?> c) {

    try {
        Field idField = c.getDeclaredField(resName);
        return idField.getInt(idField);
    } catch (Exception e) {
        e.printStackTrace();
        return -1;
    } 
}
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;
}
Python
Landon19
"""
@author: @lLandon19
"""
#Simple way to see if a year is a leap year
def leapyear(year):
    if(year%400==0):
        return True
    if(year%100==0):
        return False
    if(year%4==0):
        return True
    else:
        return False

def weekday(Year,Month,Day):
    #List with values for different months
    auxlist = (0,3,3,6,1,4,6,2,5,7,3,5)
    if(leapyear(Year) and Month<3):
        C = 0
    else:
        C = 1
    D=auxlist[Month-1] + C
    Result = round(((Year-1)+((Year-1)/4-3*((Year-1)/100+1)/4)+D+Day)%7)
    #Sunday=0, Monday=1 ...
    print(Result)
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;
}
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;
}
×Oh snap! Something wrong