This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyArray { | |
static [Symbol.hasInstance](instance) { | |
return Array.isArray(instance); | |
} | |
} | |
const arr = [1, 2, 3]; | |
console.log(arr instanceof MyArray); // true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Taken from https://h3manth.com/posts/Well-known-symbols/ | |
class Life { | |
[Symbol.toPrimitive](hint) { | |
switch (hint) { | |
case "number": | |
return 100; | |
case "string": | |
return "Hundred"; | |
case "default": | |
return true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React,{Component} from 'react' | |
class App extends Component{ | |
constructor(){ | |
super() | |
this.state = { | |
firstName : "", | |
lastName :"", | |
isFriendly:false, | |
defaultText:"This is textArea" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
from io import BytesIO | |
from PIL import Image | |
r = requests.get("https://cutewallpaper.org/21/anything-wallpapers/Anything-Wallpapers-Wallpaper-Cave.png") | |
image = Image.open(BytesIO(r.content)) | |
path = "./image."+image.format | |
try: | |
image.save(path, image.format) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pip install simplejson | |
import simplejson as json # Importing simplejson with a different name for ease of use | |
import os | |
if os.path.isfile("./ages.json") and os.stat("./ages.json").st_size !=0: # Checking if a file exists and size is not zero | |
old_file = open("./ages.json", "r+") | |
data = json.loads(old_file.read()) | |
print("Current age is:", data["age"]) | |
data["age"] = data["age"]+1 | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
newFile = open("newFile.txt", "w+") # Opening the file in writing mode | |
string = "This is the content to be written into the file" # Content to be inserted into the file | |
newFile.write(string) # Writing the content to file |