Hello everyone, Spud again. I've recently decided that I'm going to post a script a day. These scripts will be of different languages and purposes depending on what I feel like doing that day.

So here you go here's my first "Script A Day" script! This one is a pop-out element plugin for SQuery.


Code:
//Coded in Javascript

function plugFunc(results,params){
for(i=0;i < results.length; i++){
res = results[i];
res.style.top = params[0]+"px";
res.style.left = params[1]+"px";
res.style.position = "fixed";
}
return results;
}



SQPlugins.addPlugin("popOut",plugFunc);
Here's today's script. It's a "make any element draggable" script!
Here you go:

Code:
var indexcounter = 0;
function makeDraggable(element){
    element.addEventListener('mousedown', mouseDown, false);
   window.addEventListener('mouseup', mouseUp, false);
   imgs = element.getElementsByTagName("img");
   for(i in imgs){
      imgs[i].draggable = false
   }
}

function mouseUp(e){
  window.removeEventListener('mousemove', divMove, true);
}

function mouseDown(e){
  window.div = e.target;
  console.log(e.target)
  window.div.style.zIndex = ++window.indexcounter;
  window.addEventListener('mousemove', divMove, true);
  window.offsetleft = window.div.offsetLeft - e.clientX;
  window.offsettop = window.div.offsetTop - e.clientY;
}

function divMove(e){
  window.div.style.position = 'absolute';
  window.div.style.top = e.clientY + window.offsettop + 'px';
  window.div.style.left = e.clientX + window.offsetleft + 'px';
}
This looks like it's Javascript as well?

Keep it up, I look forward to seeing your accomplishments. If it's not too much, can you start commenting your code for those who are trying to learn as well?
Here's today's script. This is basically an irc bot starter kit. (some assembly required)


Code:
import socket
import sys

server = "irc.servercentral.net"       #settings
channel = "#channel-name"
botnick = "your_bot_name"

irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #defines the socket
print("connecting to: " + server)
irc.connect((server,7000))                                                         #connects to the server
irc.send("USER "+botnick+": This is a fun bot!\n") #user authentication
irc.send("NICK "+ botnick +"\n")                            #sets nickname
irc.send("PRIVMSG nickserv :iNOOPE\r\n")    #auth
irc.send("JOIN "+ channel +"\n")        #join the channel


def prvtmsg(reciever,msg): #this command is used to send a mesdsage to a specific user
    irc.send("PRIVMSG "+reciever+" :" +msg+ "\r\n")
def msg(msg):
    irc.send("PRIVMSG "+channel+" :" +msg+ "\r\n") #this will send a global message


while 1:    #puts it in a loop
   text=irc.recv(2040)  #receive the text
   print(text)#print text to console
   if text.find('PING')!= -1:                          #check if 'PING' is found
       irc.send('PONG ' + text.split()[1] + '\r\n') #returnes 'PONG' back to the server (prevents pinging out!)
   if text.find('!your_bot_name') !=-1: #you can change !your_bot_name to whatever you want
       t = text.split('!your_bot_name')
       t = t[1].strip() #this code is for getting the first word after !your_bot_name
       t = t.split(" ");
       #t[0] is the command that was issued
       #t[anything-but-0] are the command aurguments
       if t[0] == "your-command-here":
           if t[1] == "first-argument-here":
               #your actions here
I found a couple of errors with your script so I fixed it up. Study it and see what I changed they were simple errors because you skimmed over the resource you were using to make the script


Code:

import socket
import sys
import time
server = "irc.colosolutions.net"       #settings
channel = "#CHANNEL" #NOT REQUIRED BUT NEEDED IN THIS SCRIPT
botnick = "IRCNICK" #Required
RealName = botnick #this is required Tends to be BotNick

irc = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #defines the socket
print("connecting to: " + server)
irc.connect((server,6667))    #connects to the server
irc.send("USER "+ botnick +" "+ botnick +" "+ botnick +" :"+RealName+"\n") #user authentication
irc.send("NICK "+botnick+"\n")                            #sets nickname
#irc.send("PRIVMSG nickserv :iNOOPE\r\n")    #auth Not Needed if not on a server using NickServ
irc.send("JOIN "+ channel +"\n")        #join the channel

def prvtmsg(reciever,msg): #this command is used to send a mesdsage to a specific user
    irc.send("PRIVMSG "+reciever+" :" +msg+ "\r\n")
def msg(msg,channel):
    print "PRIVMSG "+channel+" :" +msg+ "\r\n"  #debug logs make a verbose later?
    irc.send("PRIVMSG "+channel+" :" +msg+ "\r\n") #this will send a global message


while 1:    #puts it in a loop
   time.sleep(.01)  #just good practice
   text=irc.recv(2040)  #receive the text
   print(text)#print text to console
   if text.find('PING')!= -1:           #check if 'PING' is found
       irc.send('PONG ' + text.split()[1] + '\r\n') #returnes 'PONG' back to the server (prevents pinging out!)
   if text.find('$') !=-1: #you can change !your_bot_name to whatever you want
       t = text.split(' :') #Splits it into 2 strings one for channel one for command set
       tchan = t[0].split("PRIVMSG") # = Channel Name
       t = t[1].strip('$\r\n') #Clear out new line garbage and the command prefix
       t = t.split() # split into a self contaned list of args
       if (len(t) <> 0):  #if we dont just have a command prefix with anythign on it
           if t[0] == "test":  #if First arg == test
               msg("Test Received",tchan[1])
Good stuff! However, as far as I can tell you heavily based your work on http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python. I strongly suggest you cite your sources in the future if that's the case; people tend to not love their work being left uncited.
I actually didn't base it off that. But your right it is very close, I can see how you'd think that
Hello all! Here's today's script! I call it CFGL (Canvas Free Game Lib)
Here's the code:

Code:
function initCFGL(){
if (!window.hasbeeninit){
document.body.style.overflow = "hidden";
window.spritenum = 0
window.hasbeeninit=1
}
}
function SpriteObj(id){
this.id = id;
this.element = document.getElementById(id);

this.moveTo = function(x,y){
this.element.style.top = y+"px";
this.element.style.left = x+"px";
}

this.setWidth = function(width){
this.element.style.width = width+"px";
}

this.setHeight = function(height){
this.element.style.height = height+"px";
}

this.onclick = function(eventType,func){
this.element.onclick = func(this);
}

this.onmousedown = function(func){
this.element.onmousedown = func(this);
}

this.onmouseup = function(func){
this.element.onmouseup = func(this);
}

this.onmouseover = function(func){
this.element.onmouseover = func(this);
}

this.draggable = function(cond){
setDraggable(this.id,cond);
}

this.setZIndex = function(index){
this.element.style.zIndex = index.toString();
}


}

var indexcounter = 0;
function setDraggable(id,cond){
    element = document.getElementById(id);
if (cond == true){
    element.addEventListener('mousedown', dragStart, false);
   window.addEventListener('mouseup', dragStop, false);
   imgs = element.getElementsByTagName("img");
   for(i in imgs){
      imgs[i].draggable = false
   }
}else{
    element.removeEventListener('mousedown', dragStart);
   console.log("False")
}
}

function dragStop(e){
  window.removeEventListener('mousemove', dragMove, true);
}

function dragStart(e){
  window.div = e.target;
  console.log(e.target)
  window.div.style.zIndex = ++window.indexcounter;
  window.addEventListener('mousemove', dragMove, true);
  window.offsetleft = window.div.offsetLeft - e.clientX;
  window.offsettop = window.div.offsetTop - e.clientY;
}

function dragMove(e){
  window.div.style.position = 'absolute';
  window.div.style.top = e.clientY + window.offsettop + 'px';
  window.div.style.left = e.clientX + window.offsetleft + 'px';
}


function newSprite(imgsrc){
document.body.innerHTML += '<div id="sprite'+window.spritenum.toString()+'"></div>';
sprite = document.getElementById('sprite'+window.spritenum.toString())
sprite.style.position = "absolute";
sprite.style.backgroundImage = "url("+imgsrc+")"
sprite.style.backgroundSize = "100% 100%";
sprite.style.width = "200px";
sprite.style.height = "200px";
return new SpriteObj('sprite'+window.spritenum.toString());
}


function removeSprite(sprite){
document.body.removeChild(sprite.element);
return 0;
}


Here's an example of how to use it:

Code:
initCFGL();
var Sprite = newSprite("image-src-here");
for (i=0,i<=100,i++){
Sprite.moveTo(i,i);
}

//this moves the sprite smoothly to (100,100)
Hey everyone, I'm sorry to inform you that I have a small project that is taking up a lot more time than expected and the chances of me posting a script are low.
Here's today's script a day. It's a single function that prints an array backwards. All it needs is to have something padding the first element and it works great!


Code:
def printback(array):
    if len(array) > 1:
        print printback(array[1:])[0]
    return array


Here's an example:

Code:
ar = [0,0,1,2,3,4,5,6,7,8,9]
printback(ar)

output:

Code:
9
8
7
6
5
4
3
2
1
0
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement