working on it ...

Filters

Explore Public Snippets

Sort by

Found 2.9M snippets

    public by jujukosto modified Feb 6, 2019  30  0  2  0

    anfm

    https://www.anfm.wordpress.fr						

    public by DinhoPutz modified Feb 5, 2019  185  2  3  0

    Calculadora de Reflorestamento em PHP

    Calcula a quanto de área a ser replantada/paga
    <html>
        <head>
            <title>Calculadora Reflorestamento</title>
    		<META charset="UTF-8" lang="pt-br">
    		<style>
    			body { font-family: Arial; }
    			table { border: none; font-weight: bold; }
    			tr, td { border: black 1px solid; }
    		</style>
    	</head>
        <body>
            <div class="Calc">
                <form method="POST">
                    <fieldset>
                        <table>
                            <legend>Calculadora de Reflorestamento</legend>
                            <tr>
                                <td>Ano</td><td>Estado</td><td>Árvores cortadas</td><td>Volume (m³)</td>
    						</tr>
                            <tr>
                                <td><input name="ano" type="text" maxlength="4" size="8"></td>
                                <td>
    								<select name="estado">
    									<option value="AC">Acre</option>
    									<option value="AL">Alagoas</option>
    									<option value="AP">Amapá</option>
    									<option value="AM">Amazonas</option>
    									<option value="BA">Bahia</option>
    									<option value="CE">Ceará</option>
    									<option value="DF">Distrito Federal</option>
    									<option value="ES">Espírito Santo</option>
    									<option value="GO">Goiás</option>
    									<option value="MA">Maranhão</option>
    									<option value="MT">Mato Grosso</option>
    									<option value="MS">Mato Grosso do Sul</option>
    									<option value="MG">Minas Gerais</option>
    									<option value="PA">Pará</option>
    									<option value="PB">Paraíba</option>
    									<option value="PR">Paraná</option>
    									<option value="PE">Pernambuco</option>
    									<option value="PI">Piauí</option>
    									<option value="RJ">Rio de Janeiro</option>
    									<option value="RN">Rio Grande do Norte</option>
    									<option value="RS">Rio Grande do Sul</option>
    									<option value="RO">Rondônia</option>
    									<option value="RR">Roraima</option>
    									<option value="SC">Santa Catarina</option>
    									<option value="SP">São Paulo</option>
    									<option value="SE">Sergipe</option>
    									<option value="TO">Tocantins</option>
    								</select>
    							</td>
                                <td><input name="arvore" type="number" max="9999" value="0"></td>
                                <td><input name="volume" type="number" max="9999" value="0"></td>
    						</tr>
                            <tr>
                                <td colspan="4"><input type="submit" value="Calcular"><input type="reset"></td>
    						</tr>
    					</table>
    				</fieldset>
    			</form>
    		</div>
    	</body>
    </html>
    
    <?php
    	
    	if($_POST != null) {
    		$ano 		= $_POST['ano'];
    		$estado 	= $_POST['estado'];
    		$arvore 	= $_POST['arvore'];
    		$volume 	= $_POST['volume'];
    		$arvoreR 	= (intval($volume) * 6);
    		$totalPagar = (intval($arvore) * 0.75);	
    		} else {
    		$ano 		= 0;
    		$estado 	= 0;
    		$arvore 	= 0;
    		$volume 	= 0;
    		$arvoreR 	= 0;
    		$totalPagar = 0;			
    	}
    	
    ?>
    <legend align='center'></legend>
    <table border='1' align='center'>
    	<tr>
    		<td colspan='6' align='center'>Resultado</td>
    	</tr>
    	<tr style='size: 16px; font-weight:bold; font-family: 'Arial Narrow';>
    		<td>Ano Base </td><td>Estado Origem </td><td>Árvores cortadas </td><td>Volume (m³) </td><td>Árvores a repor </td><td>Total a ser Pago</td>
    	</tr>
    	<tr align='center'>
    		<td><?php echo $ano			?></td>
    		<td><?php echo $estado		?></td>
    		<td><?php echo $arvore		?></td>
    		<td><?php echo $volume		?></td>
    		<td><?php echo $arvoreR		?></td>
    		<td><?php echo $totalPagar	?></td>
    	</tr>
    </table>

    public by DinhoPutz modified Feb 5, 2019  26  0  3  0

    An array of integers that returns colors

    Given an array with and objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue. Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively. Note: You are not supposed to use the library's sort function for this
    /*
    Given an array with and objects colored red, white or blue, sort them in-place so that objects of the same color are adjacent, with the colors in the order red, white and blue.
    Here, we will use the integers 0, 1, and 2 to represent the color red, white, and blue respectively.
    Note: You are not supposed to use the library's sort function for this problem.
    
    Example:
    
    Input: [2,0,2,1,1,0]
    Output: [0,0,1,1,2,2]
    Follow up:
    
    A rather straight forward solution is a two-pass algorithm using counting sort.
    First, iterate the array counting number of 0's, 1's, and 2's, then overwrite array with total number of 0's, then 1's and followed by 2's.
    Could you come up with a one-pass algorithm using only constant space?
    */
    #include<iostream>
    #include<vector>
    #include<map>
    #include<algorithm>
    using namespace std;
    class Solution {
    public:
    	static void sortColors(vector<int>&& nums) {
    		map <int, int> m_int;
    		for (const auto& num : nums) {
    			m_int[num]++;
    		}
    		nums.clear();
    		for (auto& m : m_int) {
    			for (int i = 0;i < m.second;++i) {
    				cout << m.first<<" ";
    				nums.push_back(m.first);
    			}
    		}
    
    	}
    };
    int main() {
    	Solution::sortColors({ 2,0,2,1,1,0 });
    }

    public by DinhoPutz modified Feb 5, 2019  21  0  3  0

    Substituir espaço por tração/underline no Windows com PowerShell

    Código abaixo pode ser utilizado para substituir espaço por tração/underline no Windows com PowerShell, filtrando por tipo de arquivo, ou se preferir, basta adaptar qualquer que seja a necessidade.
    # Procura por arquivo MP3 e susbtituí os espaços no nome do arquivo por traço  
    ls *.mp3 | Rename-Item -NewName { $_.name -replace " ","-" }
    
    
    # Procura por arquivo MP3 e susbtituí os espaços no nome do arquivo por underline  
    ls *.mp3 | Rename-Item -NewName { $_.name -replace " ","_" }
    
    
    # Procura por arquivo MP3 e remove os espaços  
    ls *.mp3 | Rename-Item -NewName { $_.name -replace " ","" }
    
    
    # Procura por arquivo MP3 e susbtituí os espaços no nome do arquivo por traço  
    ls *.doc | Rename-Item -NewName { $_.name -replace " ","-" }
    
    
    

    public by DinhoPutz modified Feb 5, 2019  21  0  3  0

    PHP basic function to find a word in a string

    <?php 
    
    function replaceText($text) {
      // The wanted word
    	$expected = "World"; 
    	
    	$save = str_replace($expected, "<b>World</b>", $text);
    	
    	$cont = strpos($text, $expected) !== false;
    	
    	if($cont == true){
    		echo "True: " . $save; 
    	} else { 
    		echo "False: " . $text;
    	}
    }
    
    // the call function 
    replaceText("Hello World");						

    public by sjschmalfeld modified Feb 1, 2019  558  3  4  0

    SQL Duplicates

    ;WITH cte AS
    (SELECT *, ROW_NUMBER() OVER (PARTITION BY col1, col2, col3, col4 ORDER BY (SELECT 0)) AS DuplicateRowNumber
        FROM table
    )
    SELECT * FROM cte WHERE DuplicateRowNumber > 1
    
    
    or----
    
    ;WITH cte as
    (SELECT PEOPLE.*, Loan.LoanID, ROW_NUMBER() OVER (PARTITION BY SocialSecurityNo ORDER BY SocialSecurityNo) AS DuplicateRowNumber
    FROM people INNER JOIN LOAN ON FK_PeopleID=PeopleID WHERE ISNULL(SocialSecurityNo,'') <> '' AND SocialSecurityNo <> '--' AND SocialSecurityNo <> '000-00-0000' AND loan.Status='active' )
    
    SELECT * INTO #TEMP99 FROM CTE WHERE cte.DuplicateRowNumber > 1
    
    SELECT *,b.SocialSecurityNo FROM dbo.Loan 
    	INNER JOIN (SELECT PeopleID,SocialSecurityNo FROM PEOPLE WHERE SocialSecurityNo	 
    							IN (SELECT SocialSecurityNo FROM #temp99)) b 
    	ON B.PeopleID=LOAN.FK_PeopleID
    	WHERE LOAN.Status='ACTIVE'
    
    DROP TABLE #TEMP99  
    
    
    -- Another way
    	--GET RID OF #NewAddressCandidates ADDESSES ALEADY IN THE ADDRESS TABLE
    	DELETE FROM #NewAddressCandidates WHERE EXISTS (
    	SELECT t.[Address1] 
    				,t.Address2
    				,t.City
    				,t.[State]
    				,SUBSTRING(t.Zip,1,5) AS ZIP, 
    				SUBSTRING(t.Zip,7,4) AS ZIP4 
    		FROM #NewAddressCandidates T 
    			INTERSECT  
    		SELECT [Address1] ,[Address2],[City],[State],[Zip],ZIP4 FROM dbo.[Address])				
    		
    		
    -- Another way
    	;WITH NODUP AS 
    		(SELECT  A.ADDRESS1,A.ADDRESS2,A.CITY,A.STATE,A.ZIP,A.ZIP4
    			  , row_number() OVER ( PARTITION BY  A.ADDRESS1,A.ADDRESS2,A.CITY,A.STATE,A.ZIP,A.ZIP4 ORDER BY  A.ADDRESS1,A.ADDRESS2,A.CITY,A.STATE,A.ZIP,A.ZIP4 ) AS nr
    		FROM    #NewAddressCandidates A)
    	DELETE FROM NODUP WHERE NR > 1;	
    	
    	SELECT * INTO  #UniqueNewAddresses  FROM #NewAddressCandidates WHERE EXISTS (
    	SELECT t.[Address1] 
    				,t.Address2
    				,t.City
    				,t.[State]
    				,SUBSTRING(t.Zip,1,5) AS ZIP, 
    				SUBSTRING(t.Zip,7,4) AS ZIP4 			
    		FROM #NewAddressCandidates T 
    			EXCEPT 
    		SELECT [Address1] ,[Address2],[City],[State],[Zip],ZIP4 FROM dbo.[Address])
    	
    	// Now to remove the duplicate rows, use the same table and use EXCEPT operator with an 
    	// empty result set returned by the same table	
    	// USING except operator	
    	SELECT col1,col2
      FROM DuplicateRcordTable
      EXCEPT
      SELECT col1,col2
      FROM DuplicateRcordTable WHERE 1=0
    																				

    public by RibakKan modified Feb 1, 2019  27  0  2  0

    html

    <!DOCTYPE>
    <html>
    <head>
    	<title>title</title>
    </head>
    
    <body>
    
    </body>
    </html>
    

    public by DinhoPutz modified Feb 1, 2019  32  1  3  0

    Criando / Atualizado dados no RM via SOAP com PHP

    Atualizando dados no Totvs Corpore RM via PHP com SOAP utilizando o método SaveRecord do WebServices
    <?php
    	// chamada para o webservice via Soap
    	$wsdl ='http://SERVIDOR:8051/wsDataServer/MEX?wsdl';
    	
    	// Paramêtros para iniciar a sessão
    	$soapParametros = array('login' => 'mestre',
    	'password' => 'totvs',
    	'authentication' => SOAP_AUTHENTICATION_BASIC,
    	'trace' => 1,
    	'exceptions' => true
    	);	
    	
    	// Criando objeto para fazer chamada
    	$client = new SoapClient($wsdl, $soapParametros);
    	$function = 'SaveRecord';
    	
    	// Argumentos para atualização de dados via SOAP/XML 
    	$arguments = array(array( 'SaveRecord',
    	'DataServerName' => 'RhuPessoaData',
    	'XML' => '<RhuPessoa><PPessoa><CODIGO>12</CODIGO><APELIDO>Aninha =)</APELIDO></PPessoa><VPCompl><CODPESSOA>12</CODPESSOA><IDADE>26</IDADE><PESO>62</PESO></VPCompl></RhuPessoa>',
    	'Contexto' => '?' ));
    	
    	// Converter para XML, não utilizado nesse momento é apenas um teste
    	// $xml = simplexml_load_string($arguments[0]["XML"]) or die("Erro");	
    
    	//var_dump($xml);	
    	
    	// Anotações para lembrar 
    	// $options = array('location' => 'http://350z:8051/wsDataServer.asmx');
    	// (String xmlContexto, Boolean checkRoot) em RM.Con.Conector.ConWSDataServer.
    	// SaveRecord(String DataServerName, String XML, String UserName, String UserPassword, String contexto, String emailUsuarioContexto) ) 
    	
    	// Chamada para salvamento
    	$result = $client->__soapCall($function, $arguments);
    
    	// Retorno da execução 
    	// Se tudo ocorrer como deve, vai retorno a chama primaria o objeto
    	print_r($result);
    ?>

    public by DinhoPutz modified Jan 31, 2019  191  2  3  0

    Consumir dados do RM por PHP via SOAP

    Este código faz uma consulta simples e direta via PHP / SOAP no banco de dados do Totvs RM
    <?php
    	// SOAP client
    	
    	$wsdl ='http://servidor:8051/wsDataServer/MEX?wsdl';
    	
    	$soapParametros = array('login' => 'mestre',
    	'password' => 'totvs',
    	'authentication' => SOAP_AUTHENTICATION_BASIC,
    	'trace' => 1,
    	'exceptions' => true
    	);
    	
    	$paramentros = array('DataServerName' => 'EduAlunoData', 'Filtro'=>'1=1', 'Contexto'=>'?'); 
    	
    	try{
    		$client = new SoapClient($wsdl, $soapParametros);
    		$retorno = $client->ReadView($paramentros);
    		$retorno2 =  $client->__getLastResponse();
    		echo "<pre>" . $retorno2 . "</pre>";
    	}	
    	catch (Exception $e)
    	{
    		echo "<h4>Error!</h4>";
    		echo $e -> getMessage ();
    		echo '<pre>Last response: '. $client->__getLastResponse() . '</pre>';
    	}
    

    public by DinhoPutz modified Jan 30, 2019  29  2  3  0

    Função para converter minutos para horas (SQL Oracle)

    PLSQL - SQL Oracle
    -- Criando nova função
    create or replace function converter (
        numero in  number 
    ) return varchar2
    is
        minutos varchar2(10);
    begin
        
    return 
    
    	case length 
        
         (case instr((numero / 60), '.')  
            when 2 then '0'  || substr((numero / 60), 1 ,1)
            when 3 then substr((numero / 60), 1 ,2)
        else to_char(numero / 60)
        end || '.' || lpad(mod(numero, 60), 2, 0))  
    	
    			when 4 then '0' || 
    			case instr((numero / 60), '.')  
    			when 2 then '0'  || substr((numero / 60), 1 ,1)
    			when 3 then substr((numero / 60), 1 ,2)
    		else to_char(numero / 60)
        end || '.' || lpad(mod(numero, 60), 2, 0) 
       
       else 
    		 case instr((numero / 60), '.')  
    			when 2 then '0'  || substr((numero / 60), 1 ,1)
    			when 3 then substr((numero / 60), 1 ,2)
    		else to_char(numero / 60)
        end || '.' || lpad(mod(numero, 60), 2, 0)   -- temos os minutos
       
       end ;
        
    end converter;
    /
    
    
    select  converter(valor), valor as valors from horario where  valor is not null
    • Public Snippets
    • Channels Snippets