Jump to content


Check out our Community Blogs

RhetoricalRuvim

Member Since 16 Sep 2010
Offline Last Active Oct 25 2017 03:39 PM
-----

#663666 Button Maker

Posted by RhetoricalRuvim on 06 September 2013 - 08:32 PM

I do believe this may be the wrong forum to post this in. The "JavaScript and CSS" forum is for help with your JavaScript and/or CSS code. If you want to introduce yourself, there is the Introductions forum, and if you want to discuss off-topic, non-help-me things like "hey, what do you think about ..." , then The Lounge would be the right place. If you have something specific in mind (e.g. "can you please help me find why ... doesn't work in this code?" or "I want to write ... in JavaScript, but I don't know where to start"), then this would be the right place to post the topic, but you don't seem to be asking anything specific.


Regarding your button maker, however, I do have a comment: are you ever going to implement support for JavaScript DOM code generation? I mean, you have the "Give Me My Code" button which throws HTML and CSS at the user, but why not add another code box with a JavaScript function?

For example, here's the code it produces for a basic "button" :
<a href='#' id='btn'>Button</a>
, and CSS:
#btn{
background:-webkit-linear-gradient(#00a6fc,#1734d6);
display:block;
width: 205px;
text-align:center;
height: 61px;
line-height: 61px;
border-radius: 25px;
}
; why not add another field that would output an arbitrary function?:
function (){ 
	var btn= document.createElement ("a"); 
	btn.href= "#"; 
	// no need for id= because everything's run in the DOM 
	// the programmer can add 'id' if they want to, though 
	btn.style.background= "-webkit-linear-gradient(#00a6fc,#1734d6)"; 
	btn.style.display= "block"; 
	btn.style.width= "205px"; 
	btn.style.height= "61px"; 
	btn.style.lineHeight= "61px"; 
	btn.style.borderRadius= "25px"; 
	btn.appendChild (document.createTextNode ("Button")); 
	return btn; 
} 
. I think people who prefer to work with DOM would like this better than the HTML + CSS output. Notice that there is no function name between the 'function' keyword and the argument acceptance parentheses; the function name is optional, and it's perfectly fine to do 'var f= function (x){ return x + 1; };' or something similar, at least in JavaScript.

I don't think that should be very difficult to implement, considering that you pretty much have everything else ready in your app.
  • 1


#638659 Color wheel , but with an image.

Posted by RhetoricalRuvim on 13 September 2012 - 09:06 AM

If you mean image filters, there are several ways. The basic way is to make the IMG element and put a DIV (or other) element over it with a slightly-transparent background color.

I used that idea when I was trying to make an image slightly more blue (to show that it's selected); I did something like this:
<div style="background: RGBA(0,0,255,0.5); position: ..."> ... </div>


The other (newer, requires HTML5) method is to use a CANVAS, rather, to display the image, and then use canvas pixel manipulation (https://developer.mozilla.org/en-US/docs/HTML/Canvas/Pixel_manipulation_with_canvas) to do whatever filters you want with the pixel data.

If you use the CANVAS method, however, please don't forget to include this in the webpage right before the HTML tag to make CANVAS work in Internet Explorer:
<!DOCTYPE HTML>

So something like this:
<!DOCTYPE HTML> 
<html> 
<head> 
... 
</head> 
<body> 
... 
</body> 
</html>

Here's a reference on putting images into a canvas:
https://developer.mo...al/Using_images
  • 1


#635439 I Need A Little Bit Motivation

Posted by RhetoricalRuvim on 07 August 2012 - 09:19 AM

Probably one of the best ways to learn is through experience.

Even I, after so much programming, use a lot of references because we all forget, and we all need reminders. I search online references for reminders on how to do certain things all the time, even though I've done those things at least tens of times. The more you work, the more you remind yourself of how programming is done, the more experienced you'll become.

There's no such thing as "the perfect programmer" . Some people might be better at it than others, with their experience, and they might look like they're "programmers" , but all it is is they're more experienced in the field, that's all, they have a lot of room to improve too. The point is to keep working, and reminding oneself of information that keeps fading away.


So I would say, it's okay to not remember everything off the top of your head; in my case, I work on some big projects, and I keep refreshing my mind - whenever I need to - with my references (books, online).
  • 1


#635401 New Features: Forum Home Faces + Global Sidebar

Posted by RhetoricalRuvim on 06 August 2012 - 10:57 PM

The recent discussions thing is back, nice; I missed that feature.

Does it automatically refresh every x seconds?


But yeah, I think it's so much better with that feature. Thanks for adding that.
  • 1


#634782 Gallery Problem

Posted by RhetoricalRuvim on 29 July 2012 - 01:30 PM

What do you use for the 'href' attribute of the 'next picture' and 'previous picture' links?

I suppose you're using '#' ; '#' is the address of the top of the page, so if you don't want the scroll to jump then I don't recommend using '#' .

Rather, instead of this:
<a href="#" ...
, try this:
<a style="cursor: pointer; text-decoration: underline; color: #0000FF;" ...
, and I assume you're already using the 'onclick' attribute to make the links do things.
  • 1


#633424 Program To Find 2/3 Root Of Number X Using Only Loops? Help Please :/

Posted by RhetoricalRuvim on 08 July 2012 - 03:49 PM

I don't know why you would, as even C or assembly usually don't, but if you're trying to learn then it should actually be pretty easy, especially given that 3/2 is a rational number.


First of all, to calculate x^(3/2), let's take the fact that x^(a/b) = (x^a)^(1/b). This way the program just needs to find x^a, and then finding the b root of x should be as easy as implementing Newton's Method of Approximation.


We'll need to find the intersection of f(t)=t^b and g(t)=X . The reason for this is that X is what we're trying to find the b root of and t^b is a variable to the b power (we're trying to find t; t^b = X --> t = X^(1/b)). To find the intersection, we manipulate the equation to form the following:
t^b - X = 0

We can then use Newton's Method of Approximation to find what t must be equal to, given that t is the variable and all other symbols are constant.

Newton's method is like this:
x= x - f(x) / f'(x)

The way we follow that is put in a random value (a guess) for x and evaluate the right side of the equation. Then we take that result and put it in for x. We repeat the operation, using the new x for the right side of the equation and then plug that result in for x. We keep going until we get close enough to the actual answer (the rate of change will significantly decrease as the x gets close to the actual answer).

That can be thought of as:
float now_x= 8; // Just a guess value.
float previous_x= 100;
do {
previous_x = now_x
now_x = now_x - f(now_x) / f'(now_x)
} while (... until now_x is close enough to previous_x ...);

Where f(t) is, in our case, is (t^b - X) , and f'(t) is the derivative of f(t). The derivative with respect to t of (t^b - X) is equal to (b * t^(b - 1)) .

What you'll need to do is write a function or a procedure that will do those calculations (think of a value (a guess) for now_x, loop until now_x close enough to previous_x, and in the loop {set previous_x to now_x and then calculate the new value for now_x}) to find the square root (b = 2) of X. Again, to get X you just need to cube x (easy enough to do).
  • 1


#632870 [SOLVED] [TASM] Error Handling For Null Input

Posted by RhetoricalRuvim on 30 June 2012 - 09:48 AM

Any IF ELSE statement in 'assembly' is a high-level add-on to "real" 'assembly' and is therefore not pure 'assembly'. For example, the following C code:
int x;
if (x == 1){
// do something A
} else if (x > 5){
// do something B
} else {
// do something C
}
can be expressed in 'assembly' as follows:
;; 'assuming' that AX is set to the 'x' variable
cmp ax, 1
jz do_something_A
cmp ax, 5
jg do_something_B
do_something_C:
;; do something C
jmp do_something_over

do_something_A:
;; do something A
jmp do_something_over

do_something_B:
;; do something B
jmp do_something_over

do_something_over:
;; continue executing after the IF ELSE statements

Something to note, the JZ and JE mnemonic both 'assemble' to the same opcode, and the JNZ and JNE mnemonics both 'assemble' to the same instruction opcode, so a programmer can use either the 'jump [not] if equal' and the 'jump [not] if zero' mnemonics interchangeably. I, personally, like how the JZ/JNZ mnemonics look better, so I use the '... zero' mnemonics.


Some conditions:
  • JZ/JE - Jump if equal.
  • JNZ/JNE - Jump if not equal.
  • JG - Jump if greater.
  • JNG - Jump if not greater.
  • JL - Jump if less.
  • JNL - Jump if not less.
What you need to do is scan the input string for any characters other than the ones you specified. Bit 5 of an alphabetic character indicates its case (1=lowercase, 0=capital), so you can set or clear that bit of each character, as you scan the string, to make the checking easier.

You will also need to know the terminating character the string uses. If you're using C-like strings, then the terminating character is probably 0 (null, not '0'). In case of DOS strings, it might be '$' , but I'm not a DOS expert, so I don't know that for sure.


You might use something like this:
scan each character until the character you're scanning is equal to the terminating character
for each character:
load the character into a register
AND the character with 00100000b (make it uppercase)
check if it's an alphabetic character by:
	 if the character is less than 65 or greater than 64 + 26 then it's not an alphabetic character
	 else, continue with the scanning loop

  • 1


#632178 How To Put Something On The Side Of The Screen

Posted by RhetoricalRuvim on 21 June 2012 - 05:13 PM

Have you tried CSS's position:fixed ?

Here's a bit more information about positioning:
https://developer.mo...en/CSS/position
  • 1


#629131 How Can I Cut Everything After A Specific Character?

Posted by RhetoricalRuvim on 05 May 2012 - 08:48 AM

Perhaps the explode () and implode () functions?

$a= "Hello, World!"; 
$b= explode (", ", $a); 
print $b[0]; 
print $b[1];

And implode ():
$arr= array ("Hello", "World!"); 
$text= implode (" ", $arr); 
print $text;


Also, here are links to substr () and strpos () reference:
http://www.php.net/m...tion.substr.php
http://www.php.net/m...tion.strpos.php


* * *


Also, about this:

$mytxt="test.txt";
$new_var = substr($mytxt, 0, strpos($mytxt, "_");


How is that supposed to work? Isn't that code supposed to set $new_var to $mytxt ?

If you want to cut out everything after the '.' , for example, you might do something like this:
$mytxt="test.txt";
$new_var = substr($mytxt, 0, strpos($mytxt, ".");

I didn't test the above code, but I think it should work.


Also, if the point is to cut out the file extension, why not try exploding the string with "." and then disregarding the last element, unless there is only one? Like this (more pseudo-code than PHP):
a= explode ".", filename 
length (a) = length (a) - 1 
no_extension_filename= implode ".", a

  • 1


#629130 Javascript Gallery Compatibility Issue

Posted by RhetoricalRuvim on 05 May 2012 - 08:27 AM

Well, pressing the F12 key in Internet Explorer 9 opens the debugger window. I first figured out where the error was, and then, since the code is not very easy to read, I went to that same page in Google Chrome, opened the F12 script, used the 'Pretty print' button (which made everything in that script more readable), found where that same place in the code is, and looked at it.
  • 1


#629040 Javascript Gallery Compatibility Issue

Posted by RhetoricalRuvim on 04 May 2012 - 09:51 AM

Have you tried replacing this:
return $.element(this.createElement(A)).set(<img src='http://forum.codecall.net/public/style_emoticons/default/cool.png' class='bbc_emoticon' alt='B)' />;
with this?:
return $.element(this.createElement("A")).set(<img src='http://forum.codecall.net/public/style_emoticons/default/cool.png' class='bbc_emoticon' alt='B)' />;
or this?:
return $.element(this.createElement("a")).set(<img src='http://forum.codecall.net/public/style_emoticons/default/cool.png' class='bbc_emoticon' alt='B)' />;

And also, what's 'B' ? Is that supposed to be '"B"' , or is it 'B' ?

...

After looking at the code a little more, I noticed that you're trying to make an element using HTML; if you want to do that, rather do something more like this:
var div1= document.createElement ("div"); 
div1.innerHTML= A;
That would make an element and insert your HTML into it. If you rather prefer to use DOM, this should work:
var a= document.createElement ("input"); 
a.type= "checkbox"; 
a.name= "name01"; 
a.id= "the_id_1"; 
a.checked= true; 
...


Here's a bit of the code lines surrounding that line of code:
Posted Image
  • 3


#628687 Better Pop Up Coding To Prevent Browser Blocking

Posted by RhetoricalRuvim on 30 April 2012 - 08:57 AM

I use element "windows" a lot.

What's needed for that is just an element that is absolutely-positioned and some basic math work.


Something like this:
a= new element 
a.style.position= "absolute"; 
... populate the element using either a.innerHTML= ... or a.appendChild (document.createElement ... etc. ... 
a.style.visibility= "hidden"; 
document.body.appendChild (a); 
a.style.left= (center of screen position - a.offsetWidth / 2) + "px"; 
a.style.top= (center of screen position - a.offsetHeight / 2) + "px"; 
a.style.visibility= "visible";

Also, you can use this to get the center of screen position:
(window.innerWidth / 2) + window.pageXOffset
; using innerHeight and pageYOffset would do for the other aspect of the position.
  • 1


#626221 Is There A Program That Does This?

Posted by RhetoricalRuvim on 10 April 2012 - 04:50 PM

Yeah, I guess it is a moderate task, as gregwarner mentioned.

But anyway, that type of program does exist, now that I wrote it. Here's the link (the program is open-source):
http://wbord.net/exp...ineDrawing.html
  • 1


#625749 Steam hacked

Posted by RhetoricalRuvim on 06 April 2012 - 08:53 PM

I know this is an old thread, but I thought this is relevant to the part of the conversation about MySQL injections.

I found this PHP function recently:
http://php.net/manua...cape-string.php

It says on that page that that function should be used before sending anything to the MySQL server. That function basically escapes the input, so that injections (at least the ones I'm aware of) are not possible.


Also a note, urlencode () can be used, unless you're using the LIKE keyword or similar.
  • 1


#616984 matrix task in assembly 8086

Posted by RhetoricalRuvim on 13 December 2011 - 06:28 PM

You guys, please use CODE tags next time; instead of typing this:
#include "something"

rather type this:
[noparse]
#include "something"
[/noparse]

, and CodeCall would convert that to this:
#include "something"


* * *


I don't know about the functions, but how about some JavaScript code? The language doesn't matter, for now, because we first need to think of an algorithm.


The idea is, we need to try and see what we would need to do to do the task by hand, if we were asked to, but we also need to keep in mind some of the things the computer would need to have, in order to do what we're doing.

We would start at the top-left corner, and continue scanning to the right, at first; we'll need an X variable and a Y variable to keep track of our current position within the matrix array. When we "hit" the wall on the right, we'll need to start going down, rather than going to the right.

When we "hit" the bottom wall, we'll have to start going left, instead of down. Then, when we "hit" the wall on the left, we'll start going up, instead of going left. Finally, when we "hit" the top wall again, we'll start going to the right, and the whole process starts over, as we keep "hitting" walls.


The problem is, we'll end up in an endless loop if we don't do anything to the walls; therefore, we have to move walls as we hit walls. When we hit the wall on the right, and start going down, we'll have to move the wall behind us (the top wall; since we're going down, behind us would then be up). When we hit the next wall, we move the wall that's behind us at that point, and so on.

Moving the walls closer in prevents us from going past those walls, and re-doing numbers that we already passed. That way, we know that we passed every number in the matrix when the walls are so close together - or when the walls turn inside out (for example, the left wall is to the right of the right wall) - that we no longer have space to work with.


Putting all that into numbers - which is what we'll have to use in our program - , we'll need four "walls" : xmin, xmax, ymin, and ymax .
  • xmin is the left "wall" ; it's the minimum index that x can be.
  • xmax is the right "wall" ; it's the maximum index value that x can be.
  • ymin is the top "wall" ; the minimum value y can be.
  • ymax is the bottom "wall" ; the maximum value y can be.
To move a wall, we'll just have to increment or decrement the appropriate minimum or maximum variable value.

We'll, of course, have our navigation location coordinate variables, x and y ; y is the row index, and x is the column index.

And we'll also have a variable to tell us whether we're going right (1), down (2), left (3), or up (4): state .

Finally, we'll have a variable where to store the whole string, which we can output to the screen after we're done processing the numbers.



Here's the function in JavaScript that does the above:
// Copyright (C) 2011 By RhetoricalRuvim 
function spiral (arr){ 
	var x; 
	var y; 
	var xmin= 0; 
	var xmax= arr[0].length - 1; 
	var ymin= 0; 
	var ymax= arr.length - 1; 
	var state= 1; 
	var b= ""; 
	x= xmin; 
	y= ymin; 
	while (true){ 
		while (x > xmax){ 
			x--; 
			y++; 
			ymin++; 
			state= 2; 
		} 
		while (y > ymax){ 
			y--; 
			x--; 
			xmax--; 
			state= 3; 
		} 
		while (x < xmin){ 
			x++; 
			y--; 
			ymax--; 
			state= 4; 
		} 
		while (y < ymin){ 
			y++; 
			x++; 
			xmin++; 
			state= 1; 
		} 
		if (xmax < xmin) break; 
		if (ymax < ymin) break; 
		b += arr[y][x]; 
		b += " "; 
		if (state == 1) x++; 
		if (state == 2) y++; 
		if (state == 3) x--; 
		if (state == 4) y--; 
	} 
	return b; 
}




Also, to show an example of how to use the function, here's an HTML page using that code:
<!-- 
	Copyright (C) 2011 By RhetoricalRuvim 
--> 
<html> 
	<head> 
		<title> Spiral 1 </title> 
		<script type="text/javascript" src="spiral1.js"></script> 
	</head> 
	<body> 
		<h1> Spiral 1 </h1> 
		Please enter the matrix values: <BR> 
		<textarea id="mat1" cols="40" rows="10"></textarea> <BR> 
		<button onClick="work ();"> 
			Go 
		</button> 
		<BR> <BR> <BR> <BR> 
		<div id="ans"> 
			  
		</div> 
		<script type="text/javascript"> 
			var src= document.getElementById ("mat1"); 
			var txt= document.getElementById ("ans"); 
			function work (){ 
				var text= src.value; 
				var array1= text.split ("\r\n"); 
					// Some browsers like to treat new-line character sequences as "\n" , and not 
					// the DOS-style "\r\n" , so we have to be prepared for that. 
					if (! (array1.length - 1) ) array1= text.split ("\n"); 
				var array2; 
				var i; 
				var j; 
				for (i in array1){ 
					if (isNaN (parseInt (i))) continue; 
					array1[i]= array1[i].split (" "); 
					for (j= 0; j < array1[i].length; j++) if (array1[i][j]) array1[i][j]= parseFloat (array1[i][j]); 
				} 
				txt.innerHTML= spiral (array1); 
			} 
		</script> 
	</body> 
</html>




Typically, you just need to try doing the task yourself, or at least imagine how the task will be done, and then think of how all that stuff can be represented in numbers and variables, so that you can more easily code it.

As for the next step - converting higher-level code into assembly language - I would say learn assembly language, if you haven't yet, and/or look at the 8086/8088 instruction set, and think of what instructions, and how, you can use to accomplish the things that the higher-level code does. You don't have to learn every single instruction there is, but it would be a good idea to at least become familiar with that stuff.

It would also help you gain experience if you practice reading assembly language (or other) code; that way you can debug things better, and catch mistakes more easily.
  • -1