26 ago

GeekServo

One of the cheapest and most elegant ways to control LEGO projects through IOT devices is by using GeekServos.

Below is a comparative chart of the existing GeekServos types.

  Color Servo Continuous Torque Degrees Link
Blue No Yes 2 >360 buy it
Red No Yes 2 >360 buy it
Gray Yes No 2 360 buy it
Green Yes Yes 2 >360 buy it
Gray Yes No 0.5 270 buy it
Orange Yes Yes 0.5 >360 buy it
Green Yes Yes 0.5 >360 buy it
Red No Yes 0.5 >360 buy it
26 ago

Aliexpress Clear Sold Out from WishList

This is a Python code that uses Selenium with Firefox to clear Sold Out Products from the user Wish List

#!/usr/bin/env python2.6
from selenium.webdriver.common.proxy import Proxy, ProxyType
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver
import time
from lxml import html
from lxml import etree
from tqdm import tqdm
myUser = "[username/email]"
myPassword = "[password]"
urls = list()
def getDriver(proxy=False,headless=True):
	if proxy:
		proxy = "172.16.0.1:80"
		firefox_capabilities = webdriver.DesiredCapabilities.FIREFOX
		firefox_capabilities['marionette'] = True
		firefox_capabilities['proxy'] = {
			"proxyType": "MANUAL",
			"httpProxy": proxy,
			"ftpProxy": proxy,
			"sslProxy": proxy
		}
		if headless:
			options = FirefoxOptions()
			options.add_argument("--headless")
			return webdriver.Firefox(capabilities=firefox_capabilities,options=options)
		return webdriver.Firefox(capabilities=firefox_capabilities)
	else:
		if headless:
			options = FirefoxOptions()
			options.add_argument("--headless")
			return webdriver.Firefox(options=options)
		return webdriver.Firefox()
driver = getDriver(proxy=False,headless=False)
driver.maximize_window()
driver.get('https://login.aliexpress.com/')
#Efetua o Login
element = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, "fm-login-id")))
#iframe = driver.find_element_by_id('alibaba-login-box')
#driver.switch_to_frame(iframe)
element = driver.find_element_by_id("fm-login-id")
element.send_keys(myUser)
element = driver.find_element_by_id("fm-login-password")
element.send_keys(myPassword)
driver.find_element_by_xpath("/html/body/div[2]/div/div/div/div/button").click()
driver.switch_to.default_content()
element = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, "nav-user-account")))
for i in  tqdm(range(1,51,1)):
    driver.get('https://my.aliexpress.com/wishlist/wish_list_product_list.htm?¤tGroupId=0&page='+str(i))
    links = driver.find_elements_by_xpath('/html/body/div[4]/div[2]/div[2]/ul/li[@class="product sold-out util-clearfix js-product"]/div[2]/p/a')
    for a in links:
        urls.append(a.get_attribute("href"))
for u in  tqdm(urls):
    print(u)
    driver.get(u)

https://github.com/ThiagoAlmeidaSiqueira/AliexpressClearSoldOutWishList.git

22 jul

PowerCLI + PHP + CentOS

<!--?php
//run http://127.0.0.1/vmware_power.php?install=y to install and configure powercli to apache user
if(array_key_exists ( "install" ,$_GET ) && $_GET["install"]=="y")
{
	$PowerCliCommand='export HOME=/tmp/ && pwsh -c "& {Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP \$false -Confirm:\$false; Import-Module \"VMware.VimAutomation.Core\"; Set-PowerCLIConfiguration -InvalidCertificateAction "Ignore" -Confirm:\$false; Set-PowerCLIConfiguration -DefaultVIServerMode multiple -Confirm:\$false}"';
	exec($PowerCliCommand, $Output, $ErrorReturned);
	echo(implode ( '<br-->' , $Output ));
}
else
{
	$vSphereIP = '192.168.1.200';
	$user = "myuser";
	$password = "mypassword";
 
	//$powercli_query = 'Get-VM | Select @{N=\'Name\';E={\$_.Name}},  @{N=\'UUID\';E={\$_.Config.Uuid}}   ';
	$powercli_query = 'Get-vm "XPTO-VM-MYMV" | %{\$m=\$_; \$v=Get-View \$_; \$h=Get-HardDisk \$_; \$t=Get-TagAssignment \$_; [pscustomobject] @{name=\$m.name;HostName=\$v.Guest.HostName;   Uuid=\$v.Config.Uuid; VMid=\$v.MoRef.Value;GuestId=\$v.Config.GuestId;CreateDate=\$v.Config.CreateDate;MemoryGB=\$h.Parent.MemoryGB;Numcpu=\$h.Parent.Numcpu;CapacityGB=\$h.CapacityGB;TagAssignment=(\$t | Select-object Tag -ExpandProperty Tag| select-object Category,Name,Id);Net=[pscustomobject] @{Network=\$v.Guest.Net.Network; MacAddress=\$v.Guest.Net.MacAddress; IpAddress=(\$v.Guest.Net.IpConfig.IpAddress | foreach-object {[pscustomobject] @{IpAddress=\$_.IpAddress;PrefixLength=\$_.PrefixLength }}); Connected=\$v.Guest.Net.Connected;}}}';
 
	$PowerCliCommand='export HOME=/tmp/ &amp;&amp; pwsh -c "&amp; {Import-Module VMware.VimAutomation.Core; \$teste=Connect-VIServer -Server (\"$vSphereIP\", \"$vSphereIP\") -User '.$user.' -Password \"'.$password.'\"; '.$powercli_query.'| ConvertTo-Json  -Depth 4} "';
	exec($PowerCliCommand, $Output, $ErrorReturned);
 
	header('Content-Type: application/json');
	echo(implode ( ' ' , $Output ));
}
?&gt;
20 jul

HyperV PowerShell Rest Service

ipmo 'virtualmachinemanager\virtualmachinemanager.psd1'
 
# Create a listener on port 8000
$listener = New-Object System.Net.HttpListener
$listener.Prefixes.Add('http://+:8080/') 
$listener.Start()
Get-VMMServer vmm.redemapa.agro
'Listening ...'
 
# Run until you send a GET request to /end
while ($true) {
    $context = $listener.GetContext() 
    # Capture the details about the request
    $request = $context.Request
    # Setup a place to deliver a response
    $response = $context.Response
    # Break from loop if GET request sent to /end
    if ($request.Url -match '/end') { 
        break 
    } else {
        # Split request URL to get command and options
        $requestvars = ([String]$request.Url).split("/");        
        switch($requestvars[3])
        {
            "propriedadesCustomizadasGeral" 
            {
                # Get the class name and server name from the URL and run get-WMIObject
                $result = &amp; {
                    foreach ($propriedade in $(Get-SCCustomProperty | Where-Object -Property Name -notlike "Custom*"  | Where-Object -Property Name -ne "SupportedVmGenerationForVmRole"))
                    {
                        foreach ($objeto in $(Get-VM))
                        {
                            $temp = Get-SCCustomPropertyValue -InputObject $objeto -CustomProperty $propriedade;
                            If ($temp.Name -ne $null)
                            {
                                [pscustomobject] @{
                                    Property = $temp.Name
                                    Value = $temp.Value
                                }
                            }
                        }
                    }
                }
                # Convert the returned data to JSON and set the HTTP content type to JSON
                $message = $result | ConvertTo-Json; 
                $response.ContentType = 'application/json';
            }
            "propriedadesCustomizadasVM"
            {
                $result =  &amp;{foreach ($propriedade in $(Get-SCCustomProperty | Where-Object -Property Name -notlike "Custom*"  | Where-Object -Property Name -ne "SupportedVmGenerationForVmRole"))
                {
                    $temp = Get-SCCustomPropertyValue -InputObject (Get-VM $requestvars[4])[0] -CustomProperty $propriedade;
                    If ($temp.Name -ne $null)
                    {
                        [pscustomobject] @{
                            Property = $temp.Name
                            Value = $temp.Value
                        }
                    }
                 } }
                 $message = $result | ConvertTo-Json; 
                 $response.ContentType = 'application/json';
            }
            "VM"
            {
                $result =  &amp;{get-vm $requestvars[4]}
                $message = $result | ConvertTo-Json; 
                $response.ContentType = 'application/json';
            }
            "VMs"
            {
                $result =  &amp;{get-vm | select-object name,BiosGuid, vmid ,hostname, ComputerName,StatusString, @{Name="IPv4Addresses"; Expression={ $_.VirtualNetworkAdapters.IPv4Addresses}}}
                $message = $result | ConvertTo-Json; 
                $response.ContentType = 'application/json';
            }
            default
            {
                # If no matching subdirectory/route is found generate a 404 message
                $message = "This is not the page you're looking for.";
                $response.ContentType = 'text/html' ;
            }
        }
       # Convert the data to UTF8 bytes
       [byte[]]$buffer = [System.Text.Encoding]::UTF8.GetBytes($message)
 
       # Set length of response
       $response.ContentLength64 = $buffer.length
 
       # Write response out and close
       $output = $response.OutputStream
       $output.Write($buffer, 0, $buffer.length)
       $output.Close()
   }    
}
 
#Terminate the listener
$listener.Stop()
17 maio

Apache – Log – REMOTE_ADDR, HTTP_X_FORWARDED_FOR, HTTP_CLIENTIP

Para customizar o log do apache a fim que mostrar o IP do usuário para as principais topologia de proxy, balanceador, proxy reverso, etc.

vim /etc/httpd/conf/httpd.conf
 
LogFormat "%h %{X-Forwarded-For}i %{ClientIP}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
CustomLog logs/access_log proxy
17 out

[Oracle] Criando índice espacial SIRGAS 2000

Segue a criação do índice espacial para SIRGAS 2000.

INSERT INTO mdsys.cs_srs 
(
    cs_name,
    srid,
    auth_srid,
    auth_name,
    wktext,
    cs_bounds,
    wktext3d
)
VALUES
( 
    'SIRGAS 2000 / UTM zone 22N',
    4674,
    4674,
    NULL,
    'PROJCS["SIRGAS 2000 / UTM zone 22N", GEOGCS [ "SIRGAS 2000", DATUM ["Sistema_de_Referencia_Geocentrico_para_America_del_Sur_2000", SPHEROID ["GRS 1980", 6378137.0, 298.257222101]], PRIMEM [ "Greenwich", 0.000000 ], UNIT ["Decimal Degree", 0.01745329251994328]], PROJECTION ["UTM zone 22N (EPSG OP 16022)"], PARAMETER ["Latitude_Of_Origin", 0.0], PARAMETER ["Central_Meridian", -51.0], PARAMETER ["Scale_Factor", 0.9996], PARAMETER ["False_Easting", 500000.0], PARAMETER ["False_Northing", 10000000.0], UNIT ["Meter", 1.0]]',
    mdsys.sdo_geometry(NULL,NULL,mdsys.sdo_point_type(NULL,NULL,NULL),"MDSYS"."SDO_ELEM_INFO_ARRAY"(),"MDSYS"."SDO_ORDINATE_ARRAY"()),
    NULL
);
GRANT CREATE TABLE TO [SCHEMA];
GRANT CREATE SEQUENCE TO [SCHEMA];
INSERT INTO MDSYS.SDO_GEOM_METADATA_TABLE VALUES('[SCHEMA]','[TABELA]','[COLUNA]',MDSYS.SDO_DIM_ARRAY(MDSYS.SDO_DIM_ELEMENT('LONGITUDE',-180,180,100),MDSYS.SDO_DIM_ELEMENT('LATITUDE',-90,90,100)),4674);
 
CREATE INDEX [SCHEMA].IX_[TABELA] ON [SCHEMA].[TABELA] ([COLUNA]) INDEXTYPE IS MDSYS.SPATIAL_INDEX;

Referências:

  • http://blogdomariomartinez.blogspot.com.br/2014/05/oracle-spatial-projecoes-personalizadas.html
  • http://www.spatialreference.org/ref/sr-org/6687/
20 jan

Arduino – UNO/NANO – CH340

Para programar o Arduino NANO ou UNO no Windows 8 ou 10 basta instalar o driver.

Configure na IDE do Arduino os seguintes parâmetros:

  • Placa: Arduino NANO ou Arduino UNO
  • Processador: ATmega328 ou ATmega168
  • Porta: (Verifique no gerenciador de dispositivos em qual porta se encontra)
  • Programador: AVRISP mkll

Referências:

  • https://pandoralab.com.br/arduino/driver-ch340-para-arduino/
15 ago

Ubuntu – FreeCAD – Assembly2

Instale o repositório e em seguida instale o freecad assembly2

#Instale a atualização
sudo add-apt-repository ppa:freecad-community/ppa
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install freecad-extras-assembly2