Sets in Logicblox - logicblox

Is it possible to model sets in Logicblox. Specifically, I want to have a set of Integers, say {1,4,9}, and would like to check if the set is an empty-set, and if some element belongs to the set.

Predicates actually naturally model set so if you want to model one set you can create a predicate for it as in this example:
create --unique
addblock <doc>
my_set(x) -> int(x).
my_set_not_empty() <- my_set(_).
my_set_empty() <- !my_set_not_empty().
</doc>
echo 'my_set'
print my_set
echo 'my_set_empty'
print my_set_empty
echo 'my_set_not_empty'
print my_set_not_empty
echo 'adding an element'
exec '+my_set(1).'
echo 'my_set'
print my_set
echo 'my_set_empty'
print my_set_empty
echo 'my_set_not_empty'
print my_set_not_empty
close --destroy
If you want to model sets as entities all it takes is an extra key:
create --unique
addblock <doc>
integer_set(set),integer_set:name(set:name) -> string(name).
contains(set,integer) -> integer_set(set),int(integer).
not_empty(set) <- contains(set,_).
empty(set) <- !not_empty(set), integer_set(set).
</doc>
exec <doc>
+integer_set(my_set),+integer_set:name(my_set:"my_set").
</doc>
echo "empty"
print empty
echo "not empty"
print not_empty
echo "adding elements and creating another set"
exec <doc>
+integer_set(my_set),+integer_set:name(my_set:"other_set").
+contains(my_set,1) <- integer_set:name(my_set:"my_set").
+contains(my_set,4) <- integer_set:name(my_set:"my_set").
+contains(my_set,9) <- integer_set:name(my_set:"my_set").
</doc>
echo "contains"
print contains
echo "empty"
print empty
echo "not empty"
print not_empty
close --destroy

Related

validate only alphabets using shell script in busybox

I want to validate a string which should only be Alphabets (Capital/Small). I can do it in Linux easily using Bash or Shell, but not able to validate in Busybox (OpenWRT). My piece of code is
...
#!/bin/sh
. /usr/share/libubox/jshn.sh
Info=$(cat /root/Info.json)
json_load "$Info"
json_get_var value plmn_description
echo "$value"
if [[ "$value" == [a-zA-Z] ]] ;then
echo "Valid"
else
echo "Invalid information"
fi
...
You can use case conditional construct like this:
case "$value" in
*[!a-zA-Z]*) echo invalid information ;;
*) echo valid
esac
Using Busybox awk:
$ busybox awk '{ # using busybox awk
for(i=1;i<NF;i++) # iterate all json record fields (not the last, thou)
if($i=="\"plmn_description\":" && $(i+1)~/^\"[a-zA-Z]+\",?$/) {
ret="Valid" # if "plmn_description": is followed by "alphabets"
exit # exit for performance
}
}
END {
print (ret?ret:"Invalid") # output Valid or Invalid
}' Info.json # process the json file
Output:
Valid

Sql-injection error

I am trying to do SQL-injection attack on a local website on my localhost. I am trying to get all the products from product table using the wildcard ';-- but there seems to be some problem with the query. It's giving me this error
'Warning: mysqli_fetch_assoc() expects parameter 1 to be
mysqli_result, boolean given in C:\wamp64\www\tplus\products.php on
line 151'
Here is my PHP code
<?php
//$search_value = mysqli_real_escape_string($conn,$_GET['search']);
$search_value = $_GET['search'];
$result = mysqli_query($conn,"SELECT * FROM products where p_name LIKE '%".$search_value."%'");
while ($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>";
echo $row['p_name'];
echo "</td>";
echo "<td>";
echo $row['p_price'];
echo "</td>";
echo "<td>";
echo $row['p_brand'];
echo "</td>";
echo "<td>";
echo $row['p_info'];
echo "</td>";
echo "</tr>";
}
?>
Try this
if (!$result) {
die(echo 'MySQL Error: ' . mysqli_error())
}
You need to check if
"SELECT * FROM products where p_name LIKE '%".$search_value."%'"
is a valid SQL statement.
The indication is that it is not - hence the error.
Perhaps output that string and check where the SQL statement is incorrect.

Code fails with stdin from SED

I have a bash script that finds files with particular extension and then pass the files into a function that checks every line in the file for only files that contain a library imported. For example:
function testing() {
while IFS='' read -r line; do
if [[ "$line" =~ .*log\" ]]; then
echo "log is imported in the file" $1
break
else
echo "log is not imported in the file" $1
break
fi
done < <(sed -n '/import (/,/)/p' "$1")
}
function main() {
for file in $(find "$1" -name "*.go"); do
if [[ $file == *test.go ]]; then
:
else
var1=$(testing $file)
echo "$var1"
fi
done;
}
main $1
The problem is the script works without the else block in the testing function but with the introduction of the else block in the testing function it just defaults to echoing the log is not imported in the file blah even if log is used in some of the files.
Any idea(s) on what is the problem?
Thanks.
Here is a sample input file:
package main
import (
"fmt"
"io/ioutil"
logger "log"
"net/http"
)
type webPage struct {
url string
body []byte
err error
}
...
And the output is basically to echo if log is imported or not.
You need to rewrite the logic of your testing function as it will only test the first line of the file. Indeed, each branch of the if [[ "$line" =~ .*log\" ]] has a break statement, so in practice, a break is reached whenever the first line is read.

mIRC chat bot doesn't acknowledge commands

Below is some code I have written for my ever growing bird-related chat bot.
If I use the mIRC consolse, I can execute the alias blocks (eg. //fchirp [user] ), but for some reason, the bot doesn't acknowledge somebody typing "!chirp" from the main chat window. It doesn't even execute the first //echo statement in the on-text-event.
The weirdest part is: this code worked before and I've been using it regularly. I haven't changed any part of what is shown here aside from the //echo statements which I use for debugging.
addWorms and giveWorms are both aliases I wrote and function correctly on their own. The main issue I'm running into is get the bot to do anything at all when someone types"!chirp". (It should be noted that other unrelated on-text-events earlier in the code work just fine with identical syntax.)
alias fchirp {
/writeini chirp.ini $1 First $adate
/writeini chirp.ini $1 Last $adate
/writeini chirp.ini $1 Count 1
msg $chan /w $1 Welcome to the Nest! Thanks for checking in! :D
addWorms $1
msg $chan /w $1 Type !worms to see how many you have!
//echo -a first chirp
}
alias chirp {
var %a $readini(chirp.ini, $1, Count)
var %count $calc( %a + 1 )
if ( $readini(worms.ini, $1, Breed) == $null ) {
addWorms $1
//echo -a addWorms done
}
if ( $readini(chirp.ini, $1, Last) === $adate ) { msg $chan /w $nick You've already checked in today! BabyRage | halt }
/writeini chirp.ini $1 Last $adate
/writeini chirp.ini $1 Count %count
//echo -a last/count updated
if ( $calc( $readini(chirp.ini, $1, Count) % 5 ) == 0 ) {
giveWorms $1 10
msg $chan /w $1 Welcome back! Lucky day!
}
else {
giveWorms $1 5
msg $chan /w $1 Welcome back! Here's your worms! Don't forget to !hunt ! ^_^
}
//echo -a giveWorms
}
on *:TEXT:!chirp:#: {
//echo -a acknowledged
if ( $readini(chirp.ini, $nick, First) != $null ) {
//echo -a true
chirp $nick
}
else {
//echo -a false
fchirp $nick
}
msg $chan /w $nick Don't forget to !hunt for worms! :D
}
The Event catching can be interfere by two main reasons.
Error
You have an error above your code on the same remote file. e.g. missing bracket or syntax error.
Other event already been captured
mIRC will not process event that already been matched by another pattern on the same file.
example.ini
ON *:TEXT:* dog *: echo -ag This will be called if we wrote the word dog in a sentence.
ON *:TEXT:*:#: echo -ag This will be called
ON *:TEXT:*test*: echo -ag This will never be called. Even if we wrote the word test in sentence.
You can merge your TEXT events to handle both actions, although if they aren't logic related, i would separated them for another remote file.
on *:TEXT:*:#: {
if ($1- == !chirp) {
; In here put your code.
}
; Another code over here..
; Count some stuff in here..
}
Remark: / is useless on alias/popup/remote code, and it is just for identifying text vs commands for console mIRC window.

PHP - echo inside an echo

I have a PHP if/else statement. This is the code I'm trying to echo under an else condition.
<?php $locked = ForumData::is_topic_locked($post->topic_id);
if ($locked->topic_locked == 1) {echo '<td align="right"><font color="#FF0000">Topic Locked</font><td>';}
else {
echo '<td align="left"><img src="<?php echo SITE_URL?>/lib/skins/flyeuro/images/forums/t_reply.gif"/></td>'; }
?>
The bit I'm interested to echo is this.
<img src="<?php echo SITE_URL?>
If I try this... 'echo SITE_URL'
Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';'
But this doesn't parse the image, and if I try parsing anything else, it's giving me parsing errors, which I can't fix?
How can I therefore produce an echo inside another echo?
why did you open a <?php tag again, you are already in echo line?
echo '<td align="left"><img src="'.SITE_URL.'/lib/skins/flyeuro/images/forums/t_reply.gif"/></td>';
and what is SITE_URL? Is that a variable, did you forget to put $?
echo prints out the string that you gave as parameter,
echo "foo";
As #hakre mentioned about it, . is used to concatenate strings.
$var = "foo"."bar"; //foobar
So you can use it in echo line,
$var = "foo"."bar"; //foobar
echo "foo "."bar ".$var // foo bar foobar
And It's not important weather variable defined as a string. It would be a constant variable.
define('SITE_URL', 'localhost:8080/phpvms');
echo "my website URL is ".SITE_URL; //my website URL is localhost:8080/phpvms
Remember:
<?php echo "View"; ?>
" and \
this!
Hope that's enough of a hint!#
Your problem is probably solved this way:
echo '<td align="left"><a href="',
url('Forum/create_new_post?topic_id=' . $post->topic_id . '&forum_id=' . $post->forum_id . '') ,
'"><img src="', SITE_URL,
#######################
'/lib/skins/flyeuro/images/forums/t_reply.gif"/></a></td>';
In PHP you can use constants quite like variables, e.g. to output them. You don't need to stack echoes inside each other or something.