sc(5) | |
p("Drone Commander 1.1\n") | |
p("By: Ferdinand Silva\n") | |
p("-------------------\n") | |
command_connection = netc("udp", "192.168.10.1:8889") | |
netw(command_connection, "command") | |
fl (0, 0) | |
sc(3) | |
p(">>> ") | |
sc(4) | |
cmd = r("") | |
if (!(cmd == "")) | |
if (cmd == "exit") | |
netx(command_connection) | |
ex(0) | |
fi | |
netw(command_connection, cmd) | |
response = netr(command_connection, 1024) | |
sc(5) | |
p("\nDrone response: " + response + "\n") | |
fi | |
lf |
""" | |
A Python script that converts an image file to a pure CSS image. | |
This code was based on a PHP script https://github.com/jaysalvat/image2css. | |
Sample: https://codepen.io/six519/pen/YzQOKrX | |
""" | |
import os | |
import sys | |
from PIL import Image | |
TEMP_FILE = "test.jpg" | |
if len(sys.argv) > 1: | |
img = Image.open(sys.argv[1]) | |
img.thumbnail((400, 400), Image.ANTIALIAS) | |
img.save(TEMP_FILE, "JPEG") | |
img = Image.open(TEMP_FILE) | |
print(""" | |
body { | |
background: black; | |
} | |
#img2css { | |
position: absolute; | |
top: 30px; | |
left: 50%; | |
margin-left: -200px; | |
width: 0; | |
height: 0; | |
box-shadow: | |
""") | |
for n1 in range(img.size[0]): | |
for n2 in range(img.size[1]): | |
r, g, b = img.getpixel((n1, n2)) | |
sep = ";" if n1 == (img.size[0] - 1) and n2 == (img.size[1] - 1) else "," | |
print(' {}px {}px 1px 1px #{:02x}{:02x}{:02x}{}'.format(n1, n2, r, g, b, sep)) | |
print("\n}") | |
os.remove(TEMP_FILE) |
;macro, struct and syscall uname | |
;just practicing programming in assembly language (Ferdinand Silva) | |
%macro print_info 3 | |
mov r13, %1 | |
mov r14, %2 | |
call print | |
mov r13, utsname + %3 | |
mov r14, 24 | |
call print | |
mov r13, NEW_LINE | |
mov r14, 1 | |
call print | |
%endmacro | |
section .data | |
SYS_EXIT: equ 60 | |
SYS_UNAME: equ 63 | |
SYS_WRITE: equ 1 | |
STD_IN: equ 1 | |
NEW_LINE: db 10 | |
sname: db "System Name: " | |
nname: db "Node Name: " | |
rname: db "Release: " | |
vname: db "Version: " | |
mname: db "Machine: " | |
struc UTSNAME | |
sysname: resb 64 | |
nodename: resb 64 | |
release: resb 64 | |
version: resb 64 | |
machine: resb 64 | |
endstruc | |
utsname: istruc UTSNAME | |
at sysname, db "" | |
at nodename, db "" | |
at release, db "" | |
at version, db "" | |
at machine, db "" | |
iend | |
global _start | |
section .text | |
_start: | |
call uname | |
;sysname | |
print_info sname, 13, sysname | |
;nodename | |
print_info nname, 11, nodename | |
;release | |
print_info rname, 9, release | |
;version | |
print_info vname, 9, version | |
;machine | |
print_info mname, 9, machine | |
jmp exit | |
uname: | |
mov rax, SYS_UNAME | |
mov rdi, utsname | |
syscall | |
ret | |
print: | |
mov rax, SYS_WRITE | |
mov rdi, STD_IN | |
mov rsi, r13 | |
mov rdx, r14 | |
syscall | |
ret | |
exit: | |
mov rax, SYS_EXIT | |
mov rdi, 0 | |
syscall |
;usage: ./kill2 <PID> | |
;same as `kill -n 9 <PID>` command in Linux | |
;just practicing programming in assembly language (Ferdinand Silva) | |
section .data | |
SYS_EXIT: equ 60 | |
SYS_KILL: equ 62 | |
SYS_WRITE: equ 1 | |
SIGKILL: equ 9 | |
STD_IN: equ 1 | |
INVALID: db "Usage: kill2 <PID>", 10 | |
global _start | |
section .text | |
_start: | |
pop rcx | |
cmp rcx, 2 | |
jne invalid_cmd | |
pop r14 | |
pop rsi | |
call str_to_int | |
mov r15, rax | |
call killprocess | |
jmp exit | |
;;str_to_int by: 0xAX | |
str_to_int: | |
xor rax, rax | |
mov rcx, 10 | |
next: | |
cmp [rsi], byte 0 | |
je return_str | |
mov bl, [rsi] | |
sub bl, 48 | |
mul rcx | |
add rax, rbx | |
inc rsi | |
jmp next | |
return_str: | |
ret | |
killprocess: | |
mov rax, SYS_KILL | |
mov rdi, r15 | |
mov rsi, SIGKILL | |
syscall | |
ret | |
print: | |
mov rax, SYS_WRITE | |
mov rdi, STD_IN | |
mov rsi, r13 | |
mov rdx, 20 | |
syscall | |
ret | |
invalid_cmd: | |
mov r13, INVALID | |
call print | |
exit: | |
mov rax, SYS_EXIT | |
mov rdi, 0 | |
syscall |
package main | |
import ( | |
"fmt" | |
"os" | |
"bufio" | |
"encoding/base64" | |
"encoding/json" | |
"net/http" | |
"bytes" | |
"io/ioutil" | |
) | |
//Request | |
type MainRequest struct { | |
Request []RequestArray `json:"requests"` | |
} | |
type RequestArray struct { | |
Image ImageRequest `json:"image"` | |
Feature []FeatureArray `json:"features"` | |
} | |
type ImageRequest struct { | |
Content string `json:"content"` | |
} | |
type FeatureArray struct { | |
Type string `json:"type"` | |
MaxResult int `json:"maxResults"` | |
} | |
//Response | |
type MainResponse struct { | |
Response []ResponseArray `json:"responses"` | |
} | |
type ResponseArray struct { | |
LabelAnnotation []LabelAnnotationArray `json:"labelAnnotations"` | |
} | |
type LabelAnnotationArray struct { | |
Mid string `json:"mid"` | |
Description string `json:"description"` | |
Score float64 `json:"score"` | |
Topicality float64 `json:"topicality"` | |
} | |
func main() { | |
GOOGLE_API_KEY := "<GOOGLE API KEY>" | |
GOOGLE_CLOUD_VISION_URL := "https://vision.googleapis.com/v1/images:annotate" | |
if len(os.Args) == 2 { | |
img, err := os.Open(os.Args[1]) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
defer img.Close() | |
info, _ := img.Stat() | |
size := info.Size() | |
buffer := make([]byte, size) | |
reader := bufio.NewReader(img) | |
reader.Read(buffer) | |
imgb64 := base64.StdEncoding.EncodeToString(buffer) | |
jsonRequest := MainRequest{ | |
Request: []RequestArray{ | |
{ | |
Image: ImageRequest { | |
Content: imgb64, | |
}, | |
Feature: []FeatureArray { | |
{ | |
Type: "LABEL_DETECTION", | |
MaxResult: 5, | |
}, | |
}, | |
}, | |
}, | |
} | |
request, _ := json.Marshal(&jsonRequest) | |
response, err := http.Post(GOOGLE_CLOUD_VISION_URL + "?key=" + GOOGLE_API_KEY, "application/json", bytes.NewBuffer(request)) | |
if err != nil { | |
fmt.Println(err) | |
os.Exit(1) | |
} | |
defer response.Body.Close() | |
jsonResponse, _ := ioutil.ReadAll(response.Body) | |
var data MainResponse | |
json.Unmarshal(jsonResponse, &data) | |
//fmt.Printf("The image is detected as: " + data.Response[0].LabelAnnotation[0].Description) | |
fmt.Println("========================================") | |
for _, annotation := range data.Response[0].LabelAnnotation { | |
fmt.Println("The image is detected as: " + annotation.Description) | |
} | |
fmt.Println("========================================") | |
} | |
} |