Skip to content

Instantly share code, notes, and snippets.

View asnimansari's full-sized avatar
🎯
Focusing

Asnim P Ansari asnimansari

🎯
Focusing
View GitHub Profile
const numbers = [1, 2, 3];
numbers[10] = 11;
console.log(numbers);
const foo = () => console.log("First");
const bar = () => setTimeout(() => console.log("Second"));
const baz = () => console.log("Third");
bar();
foo();
baz();
@asnimansari
asnimansari / python-context-manager-1.py
Created September 2, 2019 09:14
Simple file writing in python
file = open("hello.csv", "w")
try:
file.write('I am a disco dancer')
finally:
file.close()
@asnimansari
asnimansari / custom-context-manager-example.py
Created September 2, 2019 09:30
Custom python context manager definition & its usage
# Context manager definition
class FileOpen(object):
def __init__(self, file_name, method):
self.file_object = open(file_name, method)
def __enter__(self):
return self.file_object
def __exit__(self, value, type, traceback):
self.file_object.close()
# create an UDP server using nc on port 11090
nc -ul 11090
# check whether an UDP server is listening on 11190
nc -vz -u <hostname> 11090
# send a packet to the UDP server
echo -n "hello" | nc -4u -w1 <hostname> 1118
@asnimansari
asnimansari / Rust String and Character types
Last active May 2, 2020 08:48
Rust String & Charecter types
| | Example | # sets | Characters | Escapes |
|-----------------|-------------|------------|-------------|-------------------------|
| Character | 'H' | 0 | All Unicode | Quote & ASCII & Unicode |
| String | "hello" | 0 | All Unicode | Quote & ASCII & Unicode |
| Raw string | r#"hello"# | 0 or more* | All Unicode | N/A |
| Byte | b'H' | 0 | All ASCII | Quote & Byte |
| Byte string | b"hello" | 0 | All ASCII | Quote & Byte |
| Raw byte string | br#"hello"# | 0 or more* | All ASCII | N/A |