I have a variable inside the print function but the output is not leaving space - space

character_name = "Tom"
character_age = "50"
print("There once was a man named" +character_name+ ",")
print("he was" + character_age + "years old")
character_name = "Mike"
print("He really liked the name" + character_name + ",")
print("but didn't like being" + character_age +",")
output
There once was a man namedTom,
he was50years old
He really liked the nameMike,
but didn't like being50,
How do I put space between named and Tom or was50years

character_name = "Tom"
character_age = "50"
print("There once was a man named " +character_name+ ",")
print(" he was " + character_age + " years old")
character_name = "Mike"
print("He really liked the name " + character_name + ",")
print("but didn't like being " + character_age +",")

Try this
character_name = "Tom"
character_age = "50"
print("There once was a man named " +character_name+ ",")
print("he was " + character_age + " years old")
character_name = "Mike"
print("He really liked the name " + character_name + ",")
print("but didn't like being " + character_age +",")
Another way to solve this is to add " " between your print statements like this:
character_name = "Tom"
character_age = "50"
print("There once was a man named" + " " +character_name+ ",")
print("he was " + character_age + " " + "years old")
character_name = "Mike"
print("He really liked the name"+ " " + character_name + ",")
print("but didn't like being" + " " + character_age +",")

Related

print method in lua script/redis is not working

I am trying to execute the following script and getting the below error. Redis is running in docker
Exception in thread "main" org.redisson.client.RedisException: ERR
user_script:1: Script attempted to access nonexistent global variable
'print' script: 6f736423f082e141036b833d1f86b5a36a494611, on
#user_script:1..
I get the same error when I execute using redis CLI
127.0.0.1:6379> eval "print("Comparison is_made b/w minimum_value out of two is: ")" 0 (error) ERR user_script:1: Script attempted to
access nonexistent global variable 'print' script:
8598b7f0db450c711d3a9e73a296e331bd1ef945, on #user_script:1.
127.0.0.1:6379>
Java code. I am using Redison lib to connect to Redis and execute script.
String script = "local rate = redis.call('hget', KEYS[1], 'rate');"
+ "local interval = redis.call('hget', KEYS[1], 'interval');"
+ "local type = redis.call('hget', KEYS[1], 'type');"
+ "assert(rate ~= false and interval ~= false and type ~= false, 'RateLimiter is not initialized')"
+ "local valueName = KEYS[2];"
+ "local permitsName = KEYS[4];"
+ "if type == '1' then "
+ "valueName = KEYS[3];"
+ "permitsName = KEYS[5];"
+ "end;"
+"print(\"rate\"..rate) ;"
+"print(\"interval\"..interval) ;"
+"print(\"type\"..type); "
+ "assert(tonumber(rate) >= tonumber(ARGV[1]), 'Requested permits amount could not exceed defined rate'); "
+ "local currentValue = redis.call('get', valueName); "
+ "local res;"
+ "if currentValue ~= false then "
+ "local expiredValues = redis.call('zrangebyscore', permitsName, 0, tonumber(ARGV[2]) - interval); "
+ "local released = 0; "
+ "for i, v in ipairs(expiredValues) do "
+ "local random, permits = struct.unpack('Bc0I', v);"
+ "released = released + permits;"
+ "end; "
+ "if released > 0 then "
+ "redis.call('zremrangebyscore', permitsName, 0, tonumber(ARGV[2]) - interval); "
+ "if tonumber(currentValue) + released > tonumber(rate) then "
+ "currentValue = tonumber(rate) - redis.call('zcard', permitsName); "
+ "else "
+ "currentValue = tonumber(currentValue) + released; "
+ "end; "
+ "redis.call('set', valueName, currentValue);"
+ "end;"
+ "if tonumber(currentValue) < tonumber(ARGV[1]) then "
+ "local firstValue = redis.call('zrange', permitsName, 0, 0, 'withscores'); "
+ "res = 3 + interval - (tonumber(ARGV[2]) - tonumber(firstValue[2]));"
+ "else "
+ "redis.call('zadd', permitsName, ARGV[2], struct.pack('Bc0I', string.len(ARGV[3]), ARGV[3], ARGV[1])); "
+ "redis.call('decrby', valueName, ARGV[1]); "
+ "res = nil; "
+ "end; "
+ "else "
+ "redis.call('set', valueName, rate); "
+ "redis.call('zadd', permitsName, ARGV[2], struct.pack('Bc0I', string.len(ARGV[3]), ARGV[3], ARGV[1])); "
+ "redis.call('decrby', valueName, ARGV[1]); "
+ "res = nil; "
+ "end;"
+ "local ttl = redis.call('pttl', KEYS[1]); "
+ "if ttl > 0 then "
+ "redis.call('pexpire', valueName, ttl); "
+ "redis.call('pexpire', permitsName, ttl); "
+ "end; "
+ "return res;";
RedissonClient client = null;
try {
client = Redisson.create();
client.getRateLimiter("user1:endpoint1").setRate(
RateType.PER_CLIENT, 5, 1, RateIntervalUnit.SECONDS);
String sha1 = client.getScript().scriptLoad(script);
List<Object> keys =
Arrays.asList("user1:endpoint1", "{user1:endpoint1}:value",
"{user1:endpoint1}:value:febbb04d-6365-4cb8-b32b-8d90800cd4e6",
"{user1:endpoint1}:permits", "{user1:endpoint1}:permits:febbb04d-6365-4cb8-b32b-8d90800cd4e6");
byte[] random = new byte[8];
ThreadLocalRandom.current().nextBytes(random);
Object args[] = {1, System.currentTimeMillis(), random};
boolean res = client.getScript().evalSha(READ_WRITE, sha1, RScript.ReturnType.BOOLEAN, keys, 1,
System.currentTimeMillis(), random);
System.out.println(res);
}finally {
if(client != null && !client.isShutdown()){
client.shutdown();
}
}
checked the Lua print on the same line thread but io.write also is giving same error.
As in the comments wrote return() seems* the only way.
Example for redis-cli (set redis DB and use it in Lua)
(Collect Data and return as one string)
set LuaV 'local txt = "" for k, v in pairs(redis) do txt = txt .. tostring(k) .. " => " .. tostring(v) .. " | " end return(txt)'
Now the eval
eval "local f = redis.call('GET', KEYS[1]) return(loadstring(f))()" 1 LuaV
...shows whats in table: redis
(One long String no \n possible)
Exception: eval 'redis.log(2, _VERSION)' 0 gives out without ending the script but only on the server.
Than \n will work when you do...
set LuaV 'local txt = "" for k, v in pairs(redis) do txt = txt .. tostring(k) .. " => " .. tostring(v) .. "\n" end return(txt)'
...and the eval
eval 'local f = redis.call("GET", KEYS[1]) f = loadstring(f)() redis.log(2, f)' 1 LuaV

Problems with Google Sheets importxml

I am trying to import data from the Bscscan: https://bscscan.com/address/0x2ceDA5cf32A34702D342f0DedA0af298C1BD8049 to Google Sheets, using the formula =IMPORTXML(A1,A2), ie:
A1= https://bscscan.com/address/0x2ceDA5cf32A34702D342f0DedA0af298C1BD8049
A2= //[contains(concat( " ", #class, " " ), concat( " ", "mb-md-0", " " ))]//[contains(concat( " ", #class, " " ), concat( " ", "align-items-center", " " )) and (((count(preceding-sibling::) + 1) = 1) and parent::)]//*[contains(concat( " ", #class, " " ), concat( " ", "col-md-8", " " ))]
The problem is that every time it shows an error that says that is not possible to fetch url. I only have problems with this website, can someone please help me?

Construct queries with a condition

I am using Spring Data Neo4j and I have a repository like this:
public interface MyNeo4jRepository extends Neo4jRepository<Object, Long> {
#Query("with ['X', 'Y','Z'] as list_labels, "
+ "$appsFilter as appsList\n "
+ "MATCH (apps:) where apps.n IN appsList "
+ "MATCH (a)<-[:event]-(nodes) "
+ "WHERE any(x IN labels(nodes) WHERE x IN list_labels) "
+ "CALL apoc.path.expandConfig(nodes, { "
+ "relationshipFilter: 'R1|R2>',"
+ "labelFilter: '-l1|>l2',"
+ "maxLevel: 6,"
+ "endNodes: [apps],"
+ "uniqueness: 'NODE_PATH'}) YIELD path "
+ "unwind nodes(path) as n "
...
}
I want to create this query using conditions like this:
#Query("with ['X', 'Y','Z'] as list_labels, "
+ "$appsFilter as appsList\n "
+ "MATCH (apps:) where apps.n IN appsList "
+ "MATCH (a)<-[:event]-(nodes) "
+ "WHERE any(x IN labels(nodes) WHERE x IN list_labels) "
if (condition) + "WHERE ...." else + ""
+ "CALL apoc.path.expandConfig(nodes, { "
...
Is there a way to do it in the Neo4j query or do I have to do it with Spring composable repositories?
I think what you are looking for is the CASE construct
'WHERE ....'
+
CASE
WHEN condition1 THEN 'cypherFragement1'
WHEN condition2 THEN 'cypherFragement2'
ELSE 'cypherFragementElse'
END
+
.....
Maybe you can rewrite your entire cypher via apoc.do.when or apoc.do.case functions, which provide conditional judgment.

GenericRecord to GenericRecord using sub schema (reader schema) without Encode/Decode

I am trying an efficient way to create a GenericRecord from another GenericRecord using a subschema (reader schema) without using Encoder/Decoder. For example I have the following schemas
String fullSchema = "{\"namespace\": \"example.avro\",\n" +
" \"type\": \"record\",\n" +
" \"name\": \"User\",\n" +
" \"fields\": [\n" +
" {\"name\": \"name\", \"type\": \"string\"},\n" +
" {\"name\": \"favorite_number\", \"type\": [\"int\", \"null\"]},\n" +
" {\"name\": \"favorite_number2\", \"type\": [\"int\", \"null\"]},\n" +
" {\"name\": \"favorite_color\", \"type\": [\"string\", \"null\"]}\n" +
" ]\n" +
"}";
String readerSchema = "{\"namespace\": \"example.avro\",\n" +
" \"type\": \"record\",\n" +
" \"name\": \"User\",\n" +
" \"fields\": [\n" +
" {\"name\": \"name\", \"type\": \"string\"},\n" +
" {\"name\": \"favorite_number2\", \"type\": [\"int\", \"null\"]}\n" +
" ]\n" +
"}";
I would like to find a way to do something like this without any code and decoder, I know it is possible using a reader schema but because performance reasons, I would like to avoid this option, my real schemas are much more bigger and complex (nested structures and arrays)
GenericRecord record = new GenericData.Record(new Schema.Parser().parse(fullSchema));
record.put("name", "Jhon");
record.put("favorite_number", 1);
record.put("favorite_number2", 2);
record.put("favorite_color", "red");
GenericRecord subRecord = copy(record, readerSchema);

Vaadin Desktop Notifications

Is there any support for html5 browser 'desktop notifications' in Vaadin? I've looked for this and can't find anything specific.
I've tried something like this with no luck.
JavaScript.getCurrent().execute(
"if (window.webkitNotifications) {" +
"if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED" +
" window.webkitNotifications.createNotification(" +
" 'icon.png', 'Notification Title', 'Notification content...');" +
" } else {\n" +
" window.webkitNotifications.requestPermission();" +
" } " +
"} else { " +
" console.log('no notifications')" +
"}");
Using vaadin 8
You tried with the old api, it hasn't been supported for many versions. The new api should work:
JavaScript.getCurrent().execute(
" if (!(\"Notification\" in window)) { " +
" alert(\"This browser does not support system notifications\"); " +
" } else if (Notification.permission === \"granted\") { " +
" new Notification(\"Hi there!\"); " +
" } else if (Notification.permission !== 'denied') { " +
" Notification.requestPermission(function (permission) { " +
" if (permission === \"granted\") { " +
" Notification(\"Hi there!\"); " +
" } " +
" }); " +
" } "
);
Can't say this is a good way to do it though.
There is a plugin for vaadin 7 https://vaadin.com/directory#!addon/webnotifications you can adopt it to 8. Or create a JavaScript component or at at least a JavaScript function that will make using it easier.

Resources