Bio
Learning everything i could
Activity Feed
Created a new thread : Javascript event handling
So, while practising, I came across a code for event handling. The code is as follows:
//This generic event handler creates an object called eventHandler
var etHandler = {};
if (document.addEventListener) {
//eventHandler object has two methods added to it, add()and remove(),
etHandler.add = function(element, eventType, eventFunction) {
/**
* The add method in each model determines whether the event type is a load event, meaning that
* the function needs to be executed on page load.
*/
if (eventType == "load") {
.......
}
};// end of eventHandler.add = function()
etHandler.remove = function(element, eventType, eventFunction) {
element.detachEvent("on" + eventype, eventFunction);
}; //end of etHandler.remove = function()
}
function sendAlert() {
alert("Hello");
} //end of sendAlert()
function startTimer() {
var timerID = window.setTimeout(sendAlert,3200);
}//end of startTimer()
var mainBody = document.getElementById("mainBody");
etHandler.add(mainBody, "load", function() {
startTimer();
}
);
These are the questions I'd like to pose. We start with an empty object. etHandler is a variable that should be set to;. It's all right. The condition if (document.addEventListener) is then checked.
var etHandler = {
add: function() {
},
remove: function(){
}
};
Despite the fact that no event listeners were added to the document, this condition is met. Why does this condition return true? etHandler.add = function(element, eventType, eventFunction) follows. Why are we creating etHandler.add? When we built the etHandler object, it had no properties. It's an empty object. If we construct etHandler in this manner,
After that, we can write etHandler.add. The same question applies to etHandler.remove.
Created a new thread : Python abstraction abc plugin
I got some expertise writing in Java, however I am now compelled to develop in Python due to time constraints. What I'm attempting to do is create a class structure that extends from an abstract class Document down into numerous document kinds that, based on their type, would fetch different information from a database. Given that there are likely hundreds of distinct document kinds, I believe that utilising abstraction to offload as much functionality as possible further up the stack is my best option.
In Java, I would code something like this:
public abstract class Document(){
private String dept
private String date
...
public Document(){
...}
public abstract String writeDescription(){
...}
}
With Python, I'm not sure what my best choice is for doing anything like this. Right now, the two main options I've seen are to utilise the abc plugin.
https://docs.python.org/2/library/abc.html , Alternatively to utilise simple Python inheritance structures, such as this: Abstraction in Python?
Is it possible to complete my task without using the ABC plugin, or would it be necessary?
Created a new thread : reverse a string in Python
First have a look at the code:
def reverse(x):
output = ""
for c in x:
output = c + output
return output
print(reverse("Helo"))
This function works great in Python to invert a text; I just don't understand why or how it works.
If I iterate through a string, for example, it will usually start at "H" and work its way down to "O." How come it's going backwards here?
Created a new thread : What is the output of the given Python code
I've done coding for a few months and have reached a plateau. The code below just produces a menu and executes a few shell commands, which are then shown on the screen.
Here is the code:
#Imports
import os
import subprocess
#Set Globals for Workspace to 0
workspace = 0
absolute_path = 0
#Initally clear the screen
os.system('clear')
#Define Option 0 - Create a Workspace
def workspace_menu():
print ("Enter the name of the Workspace or type 'q' or 'quit' to return to the main menu")
print ("")
workspace_input = input(":")
if workspace_input in ("q", "quit"):
os.system('clear')
else:
#Define the current working directoy (__file__)
script_dir = os.path.dirname(__file__)
relative_path = 'workspaces/'
joined_path = os.path.join(script_dir, relative_path)
os.chdir(joined_path)
if os.path.exists(workspace_input):
print ("Directory already Exists! - Try a different name")
input("Press any key to Return to the Main Menu")
os.system('clear')
else:
make_path = os.makedirs(workspace_input)
absolute_path = joined_path + workspace_input
global absolute_path
absolute_path = absolute_path
global workspace
workspace = 1
print ("Workspace created!"), absolute_path
input("Press any Key to Continue")
os.system('clear')
return
#Define the Main Menu
def menu():
print(" 0) Add a Workspace")
print(" 1) System Tasks")
print("11) Exit")
#Define System Tasks
def system_tasks():
os.system('clear')
print(" 1) Display Local Network information")
print(" 5) Back")
system_tasks_answer = int(input(":"))
if system_tasks_answer == 1:
print("The Local Network Configuration of this OS are:")
print("")
ifconfig = subprocess.call(['/sbin/ifconfig'])
dns = subprocess.call(['cat', '/etc/resolv.conf'])
print("")
print(workspace)
lni_menu = input("Press any Key to Continue")
system_tasks()
os.system('clear')
elif system_tasks_answer == 5:
os.system('clear')
loop=True
while loop:
print (menu())
mm_answer = int(input(":"))
if mm_answer ==0:
workspace_menu()
elif mm_answer ==1:
system_tasks()
elif mm_answer ==11:
break
else:
input("You did not give a valid answer, press any key to try again")
os.system('clear')
I'd want to transfer the result of menu 1 options to a "workspace." A workspace is a user-inputted directory in which when a shell command is performed, it saves the standard input as a file to the directory specified in this guide. I'll be running over 50 distinct commands at some point, and I'd like them all to be properly saved in their respective folders. Python 3.4 is currently in use.
So far, my code can ask for user input for a workspace, which results in the creation of a relative directory. What I need is for a file to be generated.
Any advice would be much appreciated.
Replied to thread : Polymorphism In C++
@luxiferrwoo, Oh okay Got it
By saying polymorphism at all levels i mean universal polymorphism and about that i read that the templates resemble universal polymorphism on the surface but are fundamentally different. These are essentially glorified macros with minimal to no type checking (like with macros, both checking and code generation happens after expansion).
Thank you for your reply man
Created a new thread : Polymorphism In C++
I'm doing research on type systems. For this project, I'm looking at how Variants, structural subtyping, universal polymorphism, and existential polymorphism are used in popular languages. Such functions are provided by functional languages such as heskell and ocaml. But I'm curious if a popular language like C++ has the above capability. That is, how C++ is implemented.
variants
subtyping of structural elements
polymorphism at all levels
Existential polymorphism is a type of polymorphism.
Replied to thread : DLL Address
You may use a programme like Process Explorer or Cheat Engine to determine a process's DLL address. The following are the procedures to obtain the DLL address using Process Explorer:
Install and launch Process Explorer.
Choose the process for which you want the DLL address.
Choose "Lower Pane View" and then "DLLs" from the "View" menu.
Search for the DLL that interests you and take note of its base address.
You may use the DLL base address in your DLL injector to load your DLL into the target process once you have it.
The particular procedure for injecting the DLL will vary depending on the injector. Some injectors need you to enter the process ID and DLL path, however others may include a graphical user interface that allows you to pick the process and DLL file.