00:00
00:00
B1KMusic
Hi. I make games and software. I'm not on NG much, but feel free to peruse my youtube and gitlab for interesting stuff.

Braden @B1KMusic

Age 29, Male

Programmer/Musician/

fish

Earth, Milky Way

Joined on 6/19/11

Level:
10
Exp Points:
948 / 1,110
Exp Rank:
69,221
Vote Power:
5.20 votes
Rank:
Police Sergeant
Global Rank:
8,619
Blams:
42
Saves:
1,040
B/P Bonus:
12%
Whistle:
Normal
Medals:
799

B1KMusic's News

Posted by B1KMusic - March 9th, 2013


http://jsfiddle.net/B1KMusic/xf7De/

It generates a map of random colors up to 10 000 x 10 000 pixels without making the browser lag.

I spent extra time making the settings easy to understand.

You can mess around with the settings, change the size of the image, change the pixel size, and the color channel ratios, and the picture renders before your eyes, and if you like it, you can click it and save it. It can crash trying to save huge pictures, though.

Tip: In firefox, set the image size to your screen resolution, pixel size to 1, and the color channels to:

R: 0x00
G: 0x77
B: 0x00

Instant grass!

For more realistic grass, some blue should be included:

R: 0x00
G: 0x77
B: 0x33 <-- Since dark blue is kinda the color of grass shadow, this actually makes it a little more realistic

Chrome renders fast
Firefox can save massive pictures that would kill the page on chrome
IE9 works
Safari works about the same as chrome
Haven't tested Opera

Picture below is a 1280x800 "grass" picture I rendered in firefox.

Technical details:

The way it progressively renders is through the use of setTimeout and anonymous functions.

((function renderY(i){
__if(i < H){
____((function renderX(j){
______if(j < W){
________for(var k = 0; k < 100; k ++){
__________context.fillStyle = randomColor();
__________context.fillRect(j,i,1,1);
__________j++;
________}
________setTimeout(function(){renderX(j)},0)
______}
____})(j));
____i++;
____setTimeout(function(){renderY(i)},0);
__}
})(-1));

Check out this...thing I made


Posted by B1KMusic - February 26th, 2013


I found 2 epic DAWs for Ubuntu*, and soon enough I should be able to make music again!

They are called LMMS and Ardour

I'm going to use both of them and see which one I like best. If I like both of them, then I guess I'll use both

Of course, it won't have the same sound, unless I can somehow get Sytrus, or something very similar to it.

And there's a chance that the first few songs will be crappy, just like the ones I uploaded on Zzbtbest1000zZ...

If they are, I'll post them there, lol.

----

Ubuntu is the OS I switched to after Windows Vista, being the wonderful OS it is, fried my hard drive 6 months ago; it is the single best OS I've ever used

Soooo....good news!


Posted by B1KMusic - December 24th, 2012


Yeh


Posted by B1KMusic - December 22nd, 2012


Ha! It didn't happen.

2012 believers, you were all WRONG. Crazy scientists saying there will be zombies and meteors, machine rebellion and solar flares because of the galactic alignment (even though it is ~8 kpc (24,000 light years) away, which is far beyond the gravitational threshold of a black hole -_-), you were all wrong.

And I will boast and rub it in all of your faces because of your self-centered, arrogant, assertive bullshit.

This is what you get for taking a fucking 1,000 year old calendar literally

Suck it bitches, We're still alive!

I laugh. Except for the possible shootings that happened because of the panic 2012 caused in big cities like NY; I'm sure we'll be hearing about that tomorrow -_- Fuckin crazies

you, the reader, what are your thoughts on the 2012 rubbish?


Posted by B1KMusic - November 25th, 2012


Well, my computer is just a genius and never stops finding ways to troll the shit out of me.

So my computer had an aneurysm and took a dirt nap over a month ago, and I got a new OS on it to fix it (Ubuntu "Quantal Quetzal"). The new OS is really nice; secure and fast, and when I plugged the old broken hard drive in it actually read the files and didn't need to Format, unlike what my other windows computer told me.

However, there are always drawbacks.

As far as I've read, FL Studio doesn't exactly run on Linux, since it's .exe, so I have to run it through a VM running windows (it's actually very nice, but unbearably slow at times).

It also seems that my registration with image-line has magically vanished (or I forgot my info), so even If I get FL, I can't save my music because I'll only be able to use the Demo. And there i no way I'm paying 700 dollars for a new registration. Fuck that.

Lol.

I'll be trying to straighten this BS out. Until then, I can't post any music :/

I think I'll have it figured out in about a week or so.

Oh you computers :P


Posted by B1KMusic - October 6th, 2012


These are for the client. Meaning these involve any combination of HTML, Javascript and CSS

1) Multiple Keystroke detection.

Sounds complex, right? Actually no. It's easy. You just have to find out how to save the state of previous keys.

map={}
onkeydown=onkeyup=function(e){
map[e.keyCode]=e.type=='keydown'?true:false
if(map[17]&&map[16]&&map[13]){//CTRL+SHIFT+ENTER
alert(1)
}
}

You can also use names:

keys={
CTRL:17,
SHIFT:16,
ENTER:13
}

and then you can check for CTRL+SHIFT+ENTER like so:

if(map[keys['CTRL']]&&map[keys['SHIFT']]&&map[ke ys['ENTER']]){}

Q "But wait! Now every time I hit enter after the initial combo, the alert box keeps popping up!"
A This is because the alert box takes the focus from the window and fails to update since no keyup even tis received.

Q "When I try to use CTRL+D the stupid bookmarks dialog opens up"
A I also have a fix for that.

A fix for these is this:

if(map[17]&&map[16]&&map[13]){//CTRL+SHIFT+ENTER
alert(1)
map={}
return false
}

Q "what?"
A the "map={}" line clears the map object, and the "return false" line...well I should explain that a little.

a return statement in a function immediately exits a function to return information. So as a very convenient side effect, it will also suppress events. So if you put "return false" at the end of an oncontextmenu event, it suppresses the right-click context menu. If you put "return false" in an onclick event, it makes everything un-clickable. Yeah, links won't click, you can click them all you want and the link will not do anything. Put it in an onkeypress event and you can't type. So if you put return false in the end of an if statement for a combination CTRL+D (I recommend doing it for all key combos), the Bookmarks dialogue will be suppressed. The return statement can also be used for "are you sure?" dialogues.

DELETEEVERYTHING=function(){
if(!confirm('Are You Sure?')){//clicked Cancel
return false
}
//delete everything
}

So if the user clicks OK, the function will proceed, if the user clicks Cancel, it will quit without doing that

You can make a very simple keylogger to help find the id's of keys by using something like:

in HTML:
<div id=output></div>

in Javascript:
onkeydown=function(e){
output.innerText=e.keyCode
}

This way you don't have to look online for a key chart, just Press A and see 65 appear on screen.

A More advanced implementation that shows multiple keys could be written as:

HTML:
<div id=output></div>

Javascript:
map={}
onkeydown=onkeyup=function(e){
map[e.keyCode]=e.type=='keydown'?true:false
output.innerHTML=''
for(i in map){
if(map[i]){//only writes if key is "down"
output.innerHTML+=i+'<hr>'
}
}
}

This will tell you multiple keys

Note about IE: You know how almost every browser will accept a variable in an event? Internet Explorer don't play dat. To reference the event object universally, you might as well just use window.event, or event (since the reference pointer in javascript is AT the window level already), so e.keyCode becomes event.keyCode
__________________________________________
2)Saving and loading

This is pretty simple.

localStorage['key']='value'

this actually saves a key called "key" with the value of "value"

it can be loaded later on with something like:

key=localStorage['key']

key will reutrn 'value'

Of course, there is a little drawback to localStorage. Everything is saved as a string, even numbers, objects, and arrays. This is where the little known JSON object shines.

JSON, not an API. It's actually a built in object containing two functions, stringify, and parse. They do the opposite of each other

JSON.stringify({key:'value',key2:{key:'value2'}}
) will return '{"key":"value","key2":{"key":"value2"}}'
JSON.parse('{"key":"value","key2":{"key":"value2 "}}') will return the object in full glory

so if you use asdf=JSON.parse('{"key":"value","key2":{"key":"v alue2"}}'), then you can check asdf.key2.key, which will return "value2"

So this can be saved and loaded from localStorage as an object!

assuming and object named data is defined

localStorage['object']=JSON.stringify(data)

later on:

data={}

if(localStorage['object']){
data=JSON.parse(localStorage['object'])
}

Note: There is one thing to consider: do not "multi-layer" the JSON.stringify function. This has resulted in tons of errors for me, and it is not worth the hassle
________________________________
3) Random Strings

Quickly, a string is a variable of the data type Text. so "hello world" is a string. This term is universal in all programming (except joke languages like LolCode and brainfuck, but I digress).

So what am I talking about here? Go to YouTube. Click on any video. Look at the url. That video id is randomly generated at the time of the video's creation.

This can be useful for many things, including a login system, which I will get into later.

This is a function I wrote that quickly and efficiently generates a random string up to 10,000 digits without lag:

gen=function(l,chars){// l = length of string, chars = optional charset
str=''
R=function(){return Math.floor(Math.random()*10).toString()}
R2=function(){return R()+R()}
l=l||10
charset=chars||'1234567890QWERTYUIOPASDFGHJKLZXC VBNMqwertyuiopasdfghjklzxcvbnm_-'
for(i=0;i<l;i++){
char=charset[R2()]||charset[R2()]||charset[R2()]
||charset[R2()]||charset[R2()]||charset[R()]||ch arset[0]
str+=char
}
return str
}

the secret to this is that you can actually treat a string as an array. for example, 'asdf'[2] returns 'd', 'asdf'[0] returns 'a'
Another little trick is that the OR operator can be used to define defaults in functions, so asdf=value||1 will check if the variable value exists, if it doesn't, it defaults to 1. This can be daisychained, like asdf=value1||value2||1

So that almost last line attempts to grab a random index of the charset in two digits (like 32, or 97, or 01) five times, before trying one last time with a single digit, and then using the first index as a last resort, in the impossibly rare event that the random number is somehow not valid.

The result of this function is completely random. It defaults to 10 characters.

gen(11) will return what looks like a YouTube Video ID, because it is random, and 11 characters long

four samples from Google Chrome's F12 Console:

gen(11)
>"VzePmOCNExF"
gen(11)
>"pVnvGg--9Dg"
gen(11)
>"USbrKnShPlA"
gen(30)
>"UoZXRUYbWsNHGLj0kt8IOmXjNuyEAd"

Even gen(10000) will quickly return a string of 10,000 characters, with only 0.25 second delay between pressing Enter and showing the string

And back to the login system:

The way this is mostly done is as follows:

An account is created. So the user's account is stored in the database. The user account consists of all the user's account and profile information and also contains the credentials: a User Name, a Password, and a 20-50 digit Encryption Key which is generated at the time of account creation.

This can be simulated with localStorage, just have the "user" "sign up" and store the username, password, and gen(30) in an object, stringify it, and store it in localStorage to be loaded next load.

Anyways. Let's say you create an account. Your username is ASDFHAPPYFACE, and your password is applecrack5, when you hit the sign up button, an object is created, {name:'ASDFHAPPYFACE',pass:'applecrack5',key:gen (30)}

Now when you go to log in, the site fetches the object from the username, if it doesn't find it, the user does not exist. After fetching the user's account credentials, it checks the password entered against the password saved. This way I can't just type in TomFulp and automatically log in as him. Sort of obvious.

If the passwords match, then it saves a cookie to the computer with the encryption key from the database, every time the page loads it checks for this cookie. If it finds the cookie and sees an encryption key, then it will search through the database. If it finds a match, it logs you in automatically, else it does nothing. The user can then log out, which would delete the cookie.

All of this happens in less than a second.

And I did create a simulation login system which can be downloaded here. It is an .html file, and can easily be saved (if the download button doesn't work) by copy/pasting the code to notepad, hitting save, selecting ALL FILES in the dialogue under the filename input, and then you just save it as anything.html

You can sign up with multiple accounts, and each can be logged in and managed (the only thing you can do is log out and delete the "account")

Note about IE: Again Micro$oft shows their incredible stubbornness by disregarding something every other browser does. That is to say: You can't save localStorage in IE's client. The only way you can do that is by running the file on a server. So you can try (and fail) to run it on jsfiddle.net, or you can download XAMPP and figure out how to use it. Running on XAMPP, Internet Explorer does save local and session Storage.

__________________________________
4) Dimming the screen

I actually found this surprisingly simple after some thought. This just entails putting a fullscreen, transparent div element over everything, and making it visible is what dims the screen. Then you can put another box over that overlay to make a sort of message or webform. The div also doubles as obscuring everything else, so they can't be clicked.

HTML:
<div id=dim></div>

Javascript:
DIM=function(){//simple dim
dim.style.display='block'
dim.style.opacity='.9'
}
UNDIM=function(){//clicking "outside the form", or on the div element, would trigger this
dim.style.display='none'
}

OR the fancy version

DIMFANCY=function(){//this animates
dim.style.display='block'
op=0
dim.style.opacity=op
fadein=function(){
op+=.1
dim.style.opacity=op
if(op>=.9){
clearInterval(INT)
}
}
INT=setInterval(fadein,10)
}
UNDIMFANCY=function(){
op=.8
dim.style.opacity=op
fadeout=function(){
op-=.1
dim.style.opacity=op
if(op<=.1){
dim.style.display='none'
clearInterval(INT)
}
}
setInterval(fadeout,10)
}

CSS:
#dim{
position:fixed;
left:0px;
top:0px;
width:100%;
height:100%;
background:#000;
z-index:20;
display:none;
}

________________

If you see this and have a question for doing a certain thing in javascript, ask in the comments section and I will do my best to answer it with as much detail as possible.


Posted by B1KMusic - September 2nd, 2012


Are you a Web Developer? Have you always wondered "well GEE, I dunz know php, so how da fuck do I get $_GET for javascript? HOW U DO IT GOOGLE!?"?

K, check dis shit out, then.

First of all, there are two ways you can get a parameter from the URL. Well, if you wanna be a nit-picking literal sonofabitch, there are nearly infinite ways with minute differences that you can make this possible, but I digress.

One way is via function (which has been done to death, but if you want that one, check the end of this post), and one that I wrote after pondering, how do i REPLICATE php's $_GET so I can use $_GET['key'], notice the square brackets.

I wrote this code to emulate php's $_GET variable.

Before I give the snippet, I'ma explain the concept:

php grabs variables from the url via a variable called $_GET, which is an array of every key/value pair in the query string, referred to in javascript as an "Object".

Can javascript do this? Let's see:

Arrays. Check

Objects. Check

Url access. Check

Goal: create an object called $_GET, and fill it with the relevant information in the URL (while remaining nice and compact), and this is what I came up with in about 20 minutes:

/***START GET***/
try{
$_GET={}
query=location.search.split('&')
for(i in query){
reg=RegExp('([^=?&]*)=([^=?&]*)').exec(query[i])
$_GET[reg[1].replace(/%20/g,' ')]=reg[2].replace(/%20/g,' ')
}
}catch(e){/*No query string*/}
/***END GET***/

Breakdown:

try{...catch(e){...} Obviously, your website won't always have a query string (what's after the ? symbol), so this is to prevent errors

$_GET={} The first thing that must be done is defining a global, empty object to HOLD this information, otherwise it's useless

query=location.search.split('&') This splits between every & symbol and returns an array of every raw key/value pair, the lack of ? is intentional, as that would make query[0] equal to '', and make it so you have to use a few workarounds (such as array[i+1]) to do this, and it also means that you can't use a for..in loop, as there is no such thing as array['01'], unless you want to put array[parseInt(i)+1], but remember that I also want this to be compact, so that noise is out of the question.

for(i in query){
...
}
this for loop runs through the array, query, to grab every query string object

reg=RegExp('([^?&=]*)=([^?&=]*)').exec(query[i])

Yeah, if you don't understand Regular Expressions, this will probably make zero sense to you, and I feel like trying to explain it will waste time, mine and yours. But in a short summary, it's in the exec function, which can basically grab a value from the ANYWHERE you want in a string. Insanely useful function.

I don't know if you remember the split('&') from a while ago, but that left a '?' at the beginning of the first kv pair, this takes care of it by telling the exec function to ignore ALL ?'s

and the coup de grace, what all this build up was for,

$_GET[reg[1].replace(/%20/g,' ')]=reg[2].replace(/%20/g,' ')

The bare version of this is $_GET[reg[1]]=reg[2], but I thought spaces might be wanted instead of %20, hence the replace function.

Of course, the syntax is exactly the same as its php counterpart, and it will even exclude vars with '?' before them (when a '&' should be behind them) somehow (a "happy accident", if you will).

I made a demonstration file which writes everything in the url on the screen. get it HERE. This should work in any browser, as I write my code in a "weird" minimalist manner that works on anything. Yes, even the horrid Internet Explorer should run this without a problem. However, the browser I tested this on was Google Chrome, for its awesome F12 console, so if it for some reason DOESN'T work on IE, google chrome/any non-trident browser is the next best bet.

And I didn't forget the function.

The most basic form of it is this:

$_GET=function(key){
try{
return RegExp('[?&]'+key+'=([^?&]*)').exec(location.hre f)[1].replace(/%20/g,' ')
}catch(e){
return ''
}
}

what it does is, instead of creating a readily-available list of keys, it grabs a key based on what you request, so say you have a url, http://yoursite.com?ref=bullshit.com, and in javascript, you request $_GET('ref')

Short version: it will return 'bullshit.com'

Long version: it finds and looks after ? or & for key (in this case, 'ref'), and then it grabs as many non-?/& symbols as possible (([^?&]*)), and returns the result. Again, if you have a poor grasp of RegExp, you won't understand this.

I have a file from another post that uses this $_GET function, so here is that as well so you aren't left in the dark. You'll notice it also pulls off $_POST. Read this post to get more info on that.

__________________________

Also, do you find yourself saving a LOT of links into notepad like I do? If so, then you'll love this...thing I wrote. There's a screenshot below.

It has a lot of bells n whistles, so I don't know if you'll be able to figure out how to use everything, so for starters, TOP ROW, Clicking the [+] on the top will allow you to add another link to the list, and clicking the [~] on the top allows you to create categories for your links. The default is links and faves because a few browsers I tested it on (like Maxthon) when I implemented that had a weird glitch when there was only one default category, links, that would cause the list to write itself into itself, causing some stupid bullshit to happen >:(. The [-] button allows you to remove a category from the list.

BOTTOM ROW. The Clear button deletes every link in the currently selected category. The [+] and [-] buttons on the bottom will "show" and "hide" links on the list. I added this after being annoyed with all the "REMOVED" links clogging up the list. It helps make everything neat. This is the same reason I created the Swap feature, which I will Deliberate on later. The [~] link on the bottom is a little pointless, but it changes the "animation" for the top row buttons. The [S] link stands for Swap, it will swap two of the links with each other. I created this when I got fed up with A) the REMOVED links in the center, which clicking [-] on wouldn't just magically make go away, and B) not being able to sort the links' positions. The [X] button reveals and hides extra options for the [+], [-], and [~] buttons on the bottom row.

BOTTOM BOTTOM ROW. The Clear Everything Button. This has a little bastard of a button which is so evil and dangerous that I not only put it under extra options, but also both didn't bother finishing coding it to delete everything and deliberately made it a pain-in-the-ass to even click. Don't bother with it, all it does is what the normal Clear button does, plus deleting the category list and effectively leaving a shit ton of junk data on your computer. It's broken.

If you have the little patience needed to get used to this and end up using it a lot, then nothing would be worse than losing all those links for some reason (which has never happened to me so far, but I digress). Anyways, I also decided to quickly design a storage writer of sorts to dump everything from localStorage to a textarea, this can be saved to notepad to later restore everything. All that has to be done to restore it is 1) Copy the saved text from the notepad document you saved it in. 2) Paste the source into the text field where you originally got it. 3) Click the "Restore Storage" link above the text field.

Download link here (Update Sept. 8 2012: added Save and Restore Functionality and bugfix involving apostrophes.)

You can also transfer the data between computers and browsers with this Storage Writer Using the Restore link (Use the "Save Storage" link to merge existing storage rather than overwrite it).

All in all, I have found this to be very useful, and am glad I made it. Hopefully you will enjoy it, too.

HOWEVER...

Continuing the thought of how the stuff I write works on every browser I've heard of, there is one exception:

Internet Explorer has a shitty tendency to NOT working with HTML5 Web storage on localhost. Oh yeah, you heard me right, INTERNET EXPLORER CANT HAZ SAVE. Instead, you have to download XAMPP and run a file using local/sessionStorage through the apache virtual host. This is because for some stupid, retarded, money whoring reason, Microsoft thought it was a good idea to design their browser to only save cookies and Storage if it's running on a server, but not on the local machine. It can't Save Storage on the local machine, you know, what EVERY OTHER BROWSER does jut by rule of common sense. Firefox does it; safari does it; Chrome does it; Maxthon does it; opera does it; so why doesn't IE do it?

So yeah, run this and other "saver" apps on chrome (or any other webkit browser) for the best result. Unless you know how to run XAMPP...but you'd have to also edit the file and change every reference to "e" to event.keyCode since IE is a nit-picking fuck with that, too.

Moar ways to do $_GET in javascript / Link saver thing I made


Posted by B1KMusic - June 16th, 2012


You don't need php for $_GET and $_POST, because javascript is capable of both thanks to these functions I wrote:

$_GET:

function $_GET(key,def){
try{
return RegExp('[?&]'+key+'=([^?&#]*)').exec(location.hr ef)[1].replace(/%20|\+|_/g, ' ')
}catch(e){
return def?def:''
}
}

this looks into the url and utilizes the exec function to return an array based on the parentheses ("(" and ")"), ala ['...?key=value', 'value']. After doing that, it grabs the second part of the array, which returns the value. It's a simple function, so it's probably all over the place, you probably already know of its existence.

$_POST:

function $_POST(key, def){
try{
var hidden=localStorage[key]
localStorage.removeItem(key)
return hidden
}catch(e){
return def?def:''
}
}

this function acts like php's $_POST function in both presiding over a "session", and having the same security aspect. Here's how:

1 - it utilizes localStorage to save the POST data, this allows it to not expire prematurely (do not use sessionStorage)

2 - it sets a local var "hidden" to take the place of the POST data when called, and then be returned that way, this ends up deleting both variables, but returning the POST data, simple and secure.

3 - this function is supposed to be used "on load", meaning, obviously, it runs when the document loads, so you can't guess what the storage key is and make off with someone's password because it would run and the vars would get deleted before you could do that.

this isn't php, so go ahead and remove the dollar signs and obfuscate away for your facebook knockoff

In all seriousness, I'm not stupid, I know that php is for server-side scripting, and in its own ways can be a little more secure than javascript since it can't be manipulated by the client. So don't try to replace php with javascript, use both in harmony.

grab this html file, I quickly wrote it to demonstrate the GET and POST features to give you a better idea of what you can do with these functions.

Update to html: added "persistent" box too demonstrate that data can also be kept--saved to the computer--as a persistent value

When you type and press enter, it will execute that GET or POST "request", and return the information

Notice how the POST clears itself when you refresh after submitting something into it


Posted by B1KMusic - February 28th, 2012


with this javascript feature, php can go $_fuck['itself']. You probably know what I'm talking about, the $_GET[] variable in php :D.

Can also be written as a jQuery Plugin.
//////////////////////////////
function _GET(key, def){

try{
return RegExp('[?&]'+(typeof(key)=='object'?key.key:key )+'=([^#?&]*)').exec(location.href)[1].replace(/
%20|\+|\_/g, ' ')
}catch(e){
return tyepof(key)=='object'?(key.def?key.def:key._defa ult?key._default:''):(def?def:'')
}

}//Just save this into a fucking .js file you skript kiddie, you won't remember it
//////////////////////////
using Regular expressions and a shit-ton of ternary operation to keep it on one line and allow for function/jQuery syntax, this gets information from the url, ?q=ueer will be proccessed as the string "ueer" ?co=ck_joke&fa=ggot+crunch will automatically have the %20's, _'s, and +'s removed and replaced with actual fucking spaces (google does this, but don't bother searching for it, it's obfuscated to fucking hell)

Anyways, to use this, say you have the url "http://www.dumb-faggot.jewgrounds.com/?title=Wh at%20the%20Fuck"

to retrieve the title, use

var T = _GET('title', 'learn to spell you dumb faggot')

alert(T)

the window will pop up a box saying "What the Fuck"

if you misspelled "title" somehow, you'll get "learn to spell you dumb faggot" instead

Now the ternary part (condition?true:false)...

it allows to type this:

_GET({

key:'cock',

_default:'joke'

})

this will also get "joke" from a regular url, and "sucker" from ?cock=sucker&j=f&go=fuckurself

for POST...

use an invisible (css - iframe { border:0px solid white; height:0; width:0 }) iframe + ajax and jquery, duh.

WIKIPEDIAS Will go bankrupt!!!1

U Mad, wikipedos?


Posted by B1KMusic - February 3rd, 2012


say you're doing javascript or whateves, and you really don't feel like putting arrayshit[3] to get the fourth part of it, here is a quick way to skip the hassle using a second variable incase your ultra uber ZOMG EPIC ADVANCED PAGE!!!1 demands it:

var ar1 = ['first', 'second', 'third', 'fourth', 'fifth', 'sixth']
var ar2 = [0]
for(i in ar1){ // Don't Use this with JsFiddle, the fucker glitches out. Use the longer for loop (for i=0;i<object.length;i++)

ar2[i+1] = ar1[i]

}
ar1 = ar2

this actually makes the array one step ahead of the other, meaning when you type 'alert(ar2[4])', it'll come back with "Fourth" instead of "Fifth". Do not, however, use the same variable (ar1[i+1] = ar1[i]), because common sense: it'll just put the var as [0, 'second', 'second', 'second', etc].

Why not just put the zero in the original array to begin with?

If you even have to ask that, make something advanced, like a snake game, or something where you really have no control of what the array is right away. Like taking information dynamically from user input. You can't expect them to put " 0,hello,hi,hello " instead of " hello,hi,hello " in a text field just so you can conveniently place ar[1] to get the first element, no user will do that, they will get annoyed that you couldn't figure out how to NOT make them do that, and leave.