working on it ...

Filters

Explore Public Snippets

Sort by

Found 12 snippets

    public by marceloviana modified May 26, 2017  170  0  3  0

    Chamando função assincrona via console

    static void Main()
    {
        RunAsync().Wait();
    }
    
    private static async Task RunAsync()
    {
        …
    }

    public by marceloviana modified Mar 29, 2017  647  0  4  0

    Converte string em UFT-8

    byte[] bytes = Encoding.Default.GetBytes(myString);
    myString = Encoding.UTF8.GetString(bytes);
    

    public by marceloviana modified Dec 19, 2016  2733  0  4  0

    Formatar double para ,00

    //Converte double 
    
    double valor = double.Parse("100".ToString());
    
    string.Format("{0:n2}", decimal.Parse(valor.ToString())

    public by marceloviana modified Dec 5, 2016  1848  1  4  1

    Csharp ler Json e percorrer

    var url = "http://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    var sysnClient = new WebClient();
    string content = sysnClient.DownloadString(url);
    
                
    List<divida> lista_dados = new JavaScriptSerializer().Deserialize<List<cliente>>(content);
    
    string nomecompleto = "";
    
    foreach (divida registro in lista_dados) {
      nome_completo = registro.nome_completo;
    }
    
    txt_nomecompleto.Text = nomecompleto;

    public by marceloviana modified Nov 14, 2016  1367  14  4  0

    Csharp consumindo Rest + lendo JSON

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Net;
    using System.IO;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    
    namespace ExemploChatBot
    {
        public partial class Chat : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
            }
    
            protected void enviar_Click(object sender, EventArgs e)
            {
                string txt_campo_texto = campo_texto.Text;
    
                var url = "http://128.0.0.1:5000/site?id=2542&texto_digitado="+ txt_campo_texto + "";
    
                var syncClient = new WebClient();
                var content = syncClient.DownloadString(url);            
    
                dynamic registro = JObject.Parse(content);
                campo_texto.Text = registro.pergunta;
    
            }
        }
    }

    public by marceloviana modified Nov 10, 2016  2406  1  4  0

    Resolver problema de acentuação no python

    
    import sys 
    reload(sys)
    sys.setdefaultencoding('utf-8')
    

    public by marceloviana modified Oct 4, 2016  3418  3  4  1

    Python acessando banco de dados SQL Server

    ----------------INSTALAR--------------------------
    apt-get install python freetds-common
    apt-get install python-pymssql
    
    apt-get purge python-pymssql
    apt-get install freetds-dev
    pip install Cython
    pip install pymssql
    
    --------------------TESTE.PY------------------------------
    import pymssql
    
    conn=pymssql.connect(host='xx.xx.xx.xx', user='sa', password='xxxxxxxx', database='teste')
    cur=conn.cursor()	
    cur.execute("SELECT  nomes from usuarios")
    
    for row in cur:
    	print row
    
    conn.commit()	
    conn.close()
    
    	
    

    public by marceloviana modified Sep 30, 2016  3056  0  3  0

    Fazendo login com BeautifulSoup

    import mechanize
    from BeautifulSoup import BeautifulSoup
    ##from bs4 import BeautifulSoup
    import urllib2 
    import cookielib
    
    cj = cookielib.CookieJar()
    br = mechanize.Browser()
    br.set_cookiejar(cj)
    br.open("http://www.xxx.com.br/")
    
    br.select_form(nr=0)
    br.form['usuarioLogin'] = "xxxxxxxxxxxxxxx"
    br.form['usuarioSenha'] = "yyyyyyyyyyyyyyyyy"
    br.submit()
    
    pagina =  br.response().read()
    
    soup = BeautifulSoup(pagina)
    
    imagens = soup.findAll("img")
    
    for registros in imagens:
    	for registro in registros:
    		print registro

    public by marceloviana modified Sep 30, 2016  971  0  3  0

    Resolvendo problema de gcc na instalação do Scrapy

    Para o erro:
    
    error: command 'gcc' failed with exit status 1
    
    Executar os seguintes comandos
    
    apt-get install python-dev
    
    apt-get install libxml2-dev  
    apt-get install libxslt1-dev[/sourcecode]

    public by marceloviana modified Sep 29, 2016  3323  0  4  0

    Importação de CSV de histórico de cotações

    //https://br.financas.yahoo.com/q/hp?s=BRAP3.SA&a=07&b=14&c=2000&d=06&e=6&f=2016&g=d
    
    import csv 
    import MySQLdb
    
    arquivo = 'BRAP3.csv'
    I = 0
    
    with open(arquivo,) as csvfile:
    	readCSV = csv.reader(csvfile, delimiter=',')	
    	
    	for row in readCSV:
    		if(row[0] != 'Date'):
    			I = I + 1
    			##print('Data: ' + row[0] + ' Abertura: ' + row[1] + ' +Alta: ' + row[2] + ' -Baixa: ' + row[3] + ' Fechamento: ' + row[4] + ' Volume: ' + row[5])
    			db = MySQLdb.connect("192.168.1.101","******","********","*******" )
    			cursor = db.cursor()
    			
    			SQL = "insert into historico_cotacoes (data, abertura, maior_alta, maior_baixa, fechamento, volume_negociado, ajusta_fechamento,data_importacao) values ( "
    			SQL = SQL + " '" + row[0] + "', " + row[1] + ", " + row[2] + ", " + row[3] + ", " + row[4] + ", " + row[5] + ", " + row[6] +", CURRENT_DATE); " 
    			#print SQL
    			
    			cursor.execute(SQL)
    			db.commit()
    			db.close()
    			if(str(I)[-1:] == '0'):
    				print "################################## " + str(I) + " Inseridos #############################################"
    		
    		
    print "################################## " + str(I) + " Registros inseridos #############################################"                        
    • Public Snippets
    • Channels Snippets