j script runtime error: object requiered - runtime-error

I am working on the platform confirmit, which creates online surveys. This is a script node that results in the runtime error "object required", I would be grateful if you could help me fix it.. It is supposed to check whether certain codes hold 1 or 2 in the questions q2b and q3a (questions are referenced with the function f() - f(question id)[code]) - the
'//skip ?' part. Then it recodes a maximum of four of the codes into another question (h_q4) for further use.
var flag1 : boolean = false;
var flag2 : boolean = false;
//null
for(var i: int=0; i <9; i++)
{
var code = i+1;
f("h_q4")[code].set(null);
}
f("h_q4")['95'].set(null);
//skip ?
for(var k: int=1; k <16; k+=2)
{
var code = k;
if(f("q2b")[code].none("1", "2"))
flag1;
else
{
flag1 = 0;
break;
}
}
if(f("q3a")['1'].none("1", "2"))
flag2;
if(flag1 && flag2)
f("h_q4")['95'].set("1");
//recode
else
{
var fromForm = f("q2b");
var toForm = f("h_q4");
const numberOfItems : int = 4;
var available = new Set();
if(!flag1)
{
for( i = 1; i < 16; i+=2)
{
var code = i;
if(f("q2b")[i].any("1", "2"))
available.add(i);
}
}
if(!flag2)
{
available.add("9");
}
var selected = new Set();
if(available.size() <= numberOfItems)
{
selected = available;
}
else
{
while(selected.size() < numberOfItems)
{
var codes = available.members();
var randomNumber : float = Math.random()*codes.length;
var randomIndex : int = Math.floor(randomNumber);
var selectedCode = codes[randomIndex];
available.remove(selectedCode);
selected.add(selectedCode);
}
}
var codes = fromForm.domainValues();
for(var i = 0;i<codes.length;i++)
{
var code = codes[i];
if(selected.inc(code))
{
toForm[code].set("1");
}
else
{
toForm[code].set("0");
}
}
}
the first part of the code (//null) empties the 'recepient' question to ease testing
.set(), .get(), .any(), .none() are all valid

Related

I'm trying to read data from an hash table into a linked list

Im trying to read data from an global hashtable into a linked list. I cant seem to see where I went wrong. Each time I run the program, I get a runtime error.
node *locallinkedlist = NULL;
//Reading Data From the global hashtable into a local linked list to find data using binary search
for(int p = 0; p < 25; p++)
{
for(node *c = hashtable[p]; c != NULL; c = c->next)
{
if(locallinkedlist == NULL)
{
locallinkedlist = c;
}
else
{
c = locallinkedlist;
locallinkedlist = c;
}
}
}
for(node *h = locallinkedlist; h != NULL; h=h->next)
{
printf("%s",h->employeefirstname);
}
I figured it out!
I need to create a node pointer using malloc inside the inner for loop, for each employee and store each of those employee name inside the node pointer and then put it into the list. Heres my revides code!!:
node *head = NULL;
for(int i = 0; i < 25; i++)
{
for(node *j = hashtable[i]; j != NULL; j = j->next)
{
node *m = malloc(sizeof(node));
if(m == NULL)//Checking for a valid memory address
{
return 1;
}
strcpy(m->employeefirstname,j->employeefirstname);
m->next = NULL;
if(head == NULL)
{
head = m;
}
else
{
m->next = head;
head = m;
}
}
}
for(node *c = head; c != NULL; c = c->next)
{
printf("%s\n",c->employeefirstname);
}

Xamarin forms: Issue with multiple events click on same day in XamForms.Controls.Calendar

I am using XamForms.Controls.Calendar for showing events on the calendar. I have give color for special dates on the calendar using the following code:
private void AddSpecialDateWithList(List<events> list)
{
List<SpecialDate> newList = new List<SpecialDate>();
foreach (events model in list)
{
if (string.IsNullOrWhiteSpace(model.end))
{
string date = model.start;
int index = date.IndexOf('T');
if (index > 0)
{
date = date.Substring(0, index);
}
var newDate = AddDate(DateTime.Parse(date), model);
newList.Add(newDate);
newEventsList.Add(model);
}
else
{
string startDate = model.start;
int startIndex = startDate.IndexOf('T');
if (startIndex > 0)
{
startDate = startDate.Substring(0, startIndex);
}
string endDate = model.end;
int endIndex = endDate.IndexOf('T');
if (endIndex > 0)
{
endDate = endDate.Substring(0, endIndex);
}
List<DateTime> dates = GetDatesBetween(DateTime.Parse(startDate), DateTime.Parse(endDate));
for (int i = 0; i < dates.Count; i++)
{
var newDate = AddDate(dates[i], model);
newList.Add(newDate);
newEventsList.Add(model);
}
}
}
calendar.SpecialDates = newList;
}
private SpecialDate AddDate(DateTime dateTime, events model)
{
SpecialDate newDate = new SpecialDate(dateTime)
{
Selectable = true,
BackgroundColor = Color.FromHex("#fec208"),
TextColor = Color.White
};
return newDate;
}
public List<DateTime> GetDatesBetween(DateTime startDate, DateTime endDate)
{
List<DateTime> allDates = new List<DateTime>();
for (DateTime date = startDate; date <= endDate; date = date.AddDays(1))
allDates.Add(date);
return allDates;
}
I have also enabled clicked event for special dates:
private async void calendar_DateClicked(object sender, DateTimeEventArgs e)
{
int num = 0;
var specialList = calendar.SpecialDates;
var date = e.DateTime;
selectedEventsList.Clear();
foreach (SpecialDate specialDate in specialList)
{
if (specialDate.Date.Year == date.Year && specialDate.Date.Month == date.Month && specialDate.Date.Day == date.Day)
{
events model = new events();
model = newEventsList[num];
selectedEventsList.Add(model);
}
else
{
num++;
}
}
if (selectedEventsList.Count == 1)
{
await DisplayAlert("Alert", "successs.", "Ok");
}
else
{
eventTitleList.Clear();
for (int j = 0; j < selectedEventsList.Count; j++)
{
eventTitleList.Add(selectedEventsList[j].title);
}
string action = await DisplayActionSheet(null, "Cancel", null, eventTitleList.ToArray());
for (int k = 0; k < eventTitleList.Count; k++)
{
if (action == eventTitleList[k])
{
//next page
}
}
}
}
When multiple events coming on the same day I need to show the events as a pop-up window. Then the user is able to select the event from the pop-up and go to the details page. I have implemented this on the above code, but sometimes duplicates events are showing on the pop-up window.
I have created a sample project for reproducing the issue. In the sample project, on 7May, the events are Chemistry Assignment and English Project. But Chemistry Assignment is showing duplicate. 10 may events are Chemistry Assignment and Physics, but showing Chemistry Assignment and English Project. I checked this lot of times, but didn't find the reason behind this.
The error caused by that the newEventsList do not get the correct index.
Change the code in calendar_DateClicked event from:
foreach (SpecialDate specialDate in specialList)
{
if (specialDate.Date.Year == date.Year && specialDate.Date.Month == date.Month && specialDate.Date.Day == date.Day)
{
events model = new events();
model = newEventsList[num];
selectedEventsList.Add(model);
}
else
{
num++;
}
}
To:
foreach (SpecialDate specialDate in specialList)
{
if (specialDate.Date.Year == date.Year && specialDate.Date.Month == date.Month && specialDate.Date.Day == date.Day)
{
events model = new events();
model = newEventsList[num];
selectedEventsList.Add(model);
}
num++;
}
Screenshot:

Alternative to System.Web.Security.Membership.GeneratePassword in aspnetcore (netcoreapp1.0)

Is there any alternative to System.Web.Security.Membership.GeneratePassword in AspNetCore (netcoreapp1.0).
The easiest way would be to just use a Guid.NewGuid().ToString("n") which is long enough to be worthy of a password but it's not fully random.
Here's a class/method, based on the source of Membership.GeneratePassword of that works on .NET Core:
public static class Password
{
private static readonly char[] Punctuations = "!##$%^&*()_-+=[{]};:>|./?".ToCharArray();
public static string Generate(int length, int numberOfNonAlphanumericCharacters)
{
if (length < 1 || length > 128)
{
throw new ArgumentException(nameof(length));
}
if (numberOfNonAlphanumericCharacters > length || numberOfNonAlphanumericCharacters < 0)
{
throw new ArgumentException(nameof(numberOfNonAlphanumericCharacters));
}
using (var rng = RandomNumberGenerator.Create())
{
var byteBuffer = new byte[length];
rng.GetBytes(byteBuffer);
var count = 0;
var characterBuffer = new char[length];
for (var iter = 0; iter < length; iter++)
{
var i = byteBuffer[iter] % 87;
if (i < 10)
{
characterBuffer[iter] = (char)('0' + i);
}
else if (i < 36)
{
characterBuffer[iter] = (char)('A' + i - 10);
}
else if (i < 62)
{
characterBuffer[iter] = (char)('a' + i - 36);
}
else
{
characterBuffer[iter] = Punctuations[i - 62];
count++;
}
}
if (count >= numberOfNonAlphanumericCharacters)
{
return new string(characterBuffer);
}
int j;
var rand = new Random();
for (j = 0; j < numberOfNonAlphanumericCharacters - count; j++)
{
int k;
do
{
k = rand.Next(0, length);
}
while (!char.IsLetterOrDigit(characterBuffer[k]));
characterBuffer[k] = Punctuations[rand.Next(0, Punctuations.Length)];
}
return new string(characterBuffer);
}
}
}
I've omitted the do...while loop over the CrossSiteScriptingValidation.IsDangerousString. You can add that back in yourself if you need it.
You use it like this:
var password = Password.Generate(32, 12);
Also, make sure you reference System.Security.Cryptography.Algorithms.
System.Random doesn't provide enough entropy when used for security reasons.
https://cwe.mitre.org/data/definitions/331.html
Why use the C# class System.Random at all instead of System.Security.Cryptography.RandomNumberGenerator?
Please see the example below for a more secure version of #khellang version
public static class Password
{
private static readonly char[] Punctuations = "!##$%^&*()_-+[{]}:>|/?".ToCharArray();
public static string Generate(int length, int numberOfNonAlphanumericCharacters)
{
if (length < 1 || length > 128)
{
throw new ArgumentException("length");
}
if (numberOfNonAlphanumericCharacters > length || numberOfNonAlphanumericCharacters < 0)
{
throw new ArgumentException("numberOfNonAlphanumericCharacters");
}
using (var rng = RandomNumberGenerator.Create())
{
var byteBuffer = new byte[length];
rng.GetBytes(byteBuffer);
var count = 0;
var characterBuffer = new char[length];
for (var iter = 0; iter < length; iter++)
{
var i = byteBuffer[iter] % 87;
if (i < 10)
{
characterBuffer[iter] = (char)('0' + i);
}
else if (i < 36)
{
characterBuffer[iter] = (char)('A' + i - 10);
}
else if (i < 62)
{
characterBuffer[iter] = (char)('a' + i - 36);
}
else
{
characterBuffer[iter] = Punctuations[GetRandomInt(rng, Punctuations.Length)];
count++;
}
}
if (count >= numberOfNonAlphanumericCharacters)
{
return new string(characterBuffer);
}
int j;
for (j = 0; j < numberOfNonAlphanumericCharacters - count; j++)
{
int k;
do
{
k = GetRandomInt(rng, length);
}
while (!char.IsLetterOrDigit(characterBuffer[k]));
characterBuffer[k] = Punctuations[GetRandomInt(rng, Punctuations.Length)];
}
return new string(characterBuffer);
}
}
private static int GetRandomInt(RandomNumberGenerator randomGenerator)
{
var buffer = new byte[4];
randomGenerator.GetBytes(buffer);
return BitConverter.ToInt32(buffer);
}
private static int GetRandomInt(RandomNumberGenerator randomGenerator, int maxInput)
{
return Math.Abs(GetRandomInt(randomGenerator) % maxInput);
}
}

Countdown by pressing a button

How can I add a countdown in this script, by pressing the left mouse button? Every click counts minus 1. 10,9,8,7,6,5,4,3,2,1,0 example? This currently does not work in this script, and I do not understand the problem.
#pragma strict
var myTrigger : GameObject;
var myObject : GameObject;
var countAmmo : int = 10 ;
private var score : int = 10;
var guiScore : GUIText;
function Start ()
{
guiScore.text = "Score: 10";
}
function Update()
{
if(Input.GetButtonDown("Fire1"))
countAmmo = countAmmo -1;
score = countAmmo -1;
if(countAmmo == 0)
if(score == -1)
{
myObject.SetActive(false);
}
else
{
guiScore.text = "Score: -1";
myObject.SetActive(true);
}
}
I don't know exactly which language this is or in which context you are trying to achieve that, but looking at your code it seems that its only a problem with some brackets in your if-clauses. Try it, no guarantee that it's working.
#pragma strict
var myTrigger : GameObject;
var myObject : GameObject;
var countAmmo : int = 10 ;
private var score : int = 10;
var guiScore : GUIText;
function Start ()
{
guiScore.text = "Score: 10";
}
function Update()
{
if(Input.GetButtonDown("Fire1"))
{
countAmmo = countAmmo -1;
score = countAmmo -1;
guiScore.text = "Score: " + score.ToString();
if(countAmmo <= 0)
{
if(score == -1)
{
myObject.SetActive(false);
} else {
guiScore.text = "Score: -1";
}
myObject.SetActive(true);
}
}
}
This line:
guiScore.text = "Score: -1";
Should be:
guiScore.text = "Score:" + score;
#pragma strict
var myTrigger : GameObject;
var myObject : GameObject;
var countAmmo : int = 10 ;
private var score : int = 10;
var guiScore : GUIText;
function Start ()
{
guiScore.text = "Score: " + score.toString();
}
function Update()
{
if(Input.GetButtonDown("Fire1"))
countAmmo--;
score = countAmmo - 1;
if(countAmmo == 0)
{
if(score == -1)
{
myObject.SetActive(false);
}
else
{
guiScore.text = "Score: " + score.ToString();
myObject.SetActive(true);
}
}
}

How can I determine network and broadcast address from the IP address and subnet mask?

For example:
IP Address: 130.45.34.36
Mask: 255.255.240.0
What would be Net ID/Subnet Address, and
Broadcast Address?
Let's write both in binary:
130.45.34.36 = 10000010.00101101.00100010.00100100
255.255.240.0 = 11111111.11111111.11110000.00000000
A bitwise AND between the two would give us the network address:
10000010.00101101.00100010.00100100 (ip address)
AND
11111111.11111111.11110000.00000000 (subnet mask)
=
10000010.00101101.00100000.00000000 = 130.45.32.0 (the resulting network address)
A bitwise OR between the network address and the inverted subnet mask would give us the broadcast address:
10000010.00101101.00100000.00000000 (netadress)
OR
00000000.00000000.00001111.11111111 (inverted subnet mask)
=
10000010.00101101.00101111.11111111 = 130.45.47.255 (broadcast address)
var network = calculateNetworkIP("192.168.0.101", "255.255.255.0");
var broadcast = calculateBroadcastIP("192.168.0.101", "255.255.255.0");
function calculateNetworkIP(ipAddress, maskIP){
var binaryIP = convertIPToBinaryIP(ipAddress);
var maskBinaryIP = convertIPToBinaryIP(maskIP);
var binaryNetwork = [];
for (var j = 0; j < maskBinaryIP.length; j++) {
binaryNetwork.push(bitwiseAND(binaryIP[j], maskBinaryIP[j]));
}
var NetworkIPArr = convertBinaryIPToDecIP(binaryNetwork);
var NetworkIPStr = "";
for (var k = 0; k < NetworkIPArr.length; k++) {
NetworkIPStr += NetworkIPArr[k]+".";
}
return NetworkIPStr.slice(0, -1);
}
function calculateBroadcastIP(ipAddress, maskIP){
var binaryIP = convertIPToBinaryIP(ipAddress);
var maskBinaryIP = convertIPToBinaryIP(maskIP);
var invertedMark = [];
for (var i = 0; i < maskBinaryIP.length; i++) {
invertedMark.push(invertedBinary(maskBinaryIP[i]));
}
var binaryBroadcast = [];
for (var j = 0; j < maskBinaryIP.length; j++) {
binaryBroadcast.push(bitwiseOR(binaryIP[j], invertedMark[j]));
}
var broadcastIPArr = convertBinaryIPToDecIP(binaryBroadcast);
var broadcastIPStr = "";
for (var k = 0; k < broadcastIPArr.length; k++) {
broadcastIPStr += broadcastIPArr[k]+".";
}
return broadcastIPStr.slice(0, -1);
}
function invertedBinary(number){
var no = number+"";
var noArr = no.split("");
var newNo = "";
for(var i = 0; i < noArr.length; i++){
if(noArr[i] == "0"){
newNo += "1";
}else{
newNo += "0";
}
}
return newNo;
}
function bitwiseAND(firstBinary, secondBinary){
var firstArr = [];
var secondArr = [];
firstArr = firstBinary.split("");
secondArr = secondBinary.split("");
var newAdded = "";
for(var i = 0; i < firstArr.length; i++){
if(firstArr[i]+"+"+secondArr[i] == "1+0"){
newAdded += "0";
}else if(firstArr[i]+"+"+secondArr[i] == "0+1"){
newAdded += "0";
}else if(firstArr[i]+"+"+secondArr[i] == "1+1"){
newAdded += "1";
}else if(firstArr[i]+"+"+secondArr[i] == "0+0"){
newAdded += "0";
}
}
return newAdded;
}
function bitwiseOR(firstBinary, secondBinary){
var firstArr = [];
var secondArr = [];
firstArr = firstBinary.split("");
secondArr = secondBinary.split("");
var newAdded = "";
for(var i = 0; i < firstArr.length; i++){
if(firstArr[i]+"+"+secondArr[i] == "1+0"){
newAdded += "1";
}else if(firstArr[i]+"+"+secondArr[i] == "0+1"){
newAdded += "1";
}else if(firstArr[i]+"+"+secondArr[i] == "1+1"){
newAdded += "1";
}else if(firstArr[i]+"+"+secondArr[i] == "0+0"){
newAdded += "0";
}
}
return newAdded;
}
function convertBinaryIPToDecIP(binaryIPArr){
var broadcastIP = [];
for (var i = 0; i < binaryIPArr.length; i++) {
broadcastIP.push(parseInt(parseInt(binaryIPArr[i]), 2));
}
return broadcastIP;
}
function convertIPToBinaryIP(ipAddress) {
var ipArr = ipAddress.split(".");
var binaryIP = [];
for (var i = 0; i < ipArr.length; i++) {
var binaryNo = parseInt(ipArr[i]).toString(2);
if(binaryNo.length == 8){
binaryIP.push(binaryNo);
}else{
var diffNo = 8 - binaryNo.length;
var createBinary = '';
for (var j = 0; j < diffNo; j++) {
createBinary += '0';
}
createBinary += binaryNo;
binaryIP.push(createBinary);
}
}
return binaryIP;
}
Code example based on Malt's answer:
const
ipadr = '130.45.34.36',
subnet = '255.255.240.0',
ipadrs = ipadr.split('.'),
subnets = subnet.split('.');
let networks = [],
broadcasts = [];
for (let i in ipadrs) {
networks[i] = ipadrs[i] & subnets[i];
}
console.log('netaddress: ', networks.join('.')) // netaddress: 130.45.32.0
for (let i in networks) {
broadcasts[i] = networks[i] | ~subnets[i] + 256;
}
console.log('broadcast address: ', broadcasts.join('.')) // broadcast address: 130.45.47.255
Another short cut for broadcast address calculation after getting netwotk address is:
calculate total no of hosts (in this case it is 2^12 = 4096)
Divide it by 256(in this case it is 16) and add the result - 1(in this case 15) in *corresponding octet(in this case second octet i.e.
32+15=47) and make other octet 255
*we can get the corresponding octet by looking at the no of hosts. e.g if the no of hosts are greater than 256 then we have to add it to the 2nd octet of network address and so on
typescript version
function getBroadcastAddress({ address, netmask }: NetworkInterfaceInfo) {
const addressBytes = address.split(".").map(Number);
const netmaskBytes = netmask.split(".").map(Number);
const subnetBytes = netmaskBytes.map(
(_, index) => addressBytes[index] & netmaskBytes[index]
);
const broadcastBytes = netmaskBytes.map(
(_, index) => subnetBytes[index] | (~netmaskBytes[index] + 256)
);
return broadcastBytes.map(String).join(".")
}
/*
// test
getBroadcastAddress({ address: "192.168.1.93", netmask: "255.255.255.0" }) == '192.168.1.255'
*/

Resources