Web Dev Questions That Don't Need Their Own Thread v4
5,001 replies, posted
[QUOTE=CBastard;44275120]@lkymky
[code]
$quotes = array('One quote', 'And another');
shuffle($quotes); // re-order the quotes array
$quote = reset($quotes); // get the first value in the array
[/code]
Random numbers can repeat, they have no memory of what came before, it's only at a significantly large sample they actually level.
[code]
session_start(); // remove if you've already called this
$quotes = array('One quote', 'And another');
// if no session is set start at a random position in the array
if(!isset($_SESSION['quote_index'])){
$_SESSION['quote_index'] = rand(0, count($quotes)-1);
}
$quote = $quotes[$_SESSION['quote_index']];
$_SESSION['quote_index']++; // Increment position
// If the index is longer than the number of quotes set back to zero
if($_SESSION['quote_index'] == count($quotes)){
$_SESSION['quote_index'] = 0;
}
echo $quote;
[/code]
This code will start at a random position and then cycle through the quotes. There are other ways to make this more random though.[/QUOTE]
Interestingly enough, after reading..
[QUOTE=RusselG;44273208]its pseudorandom.[/QUOTE]
I ended up going on wikipedia and reading what pseudorandom really ment, I've literally been up all night reading about this because its facinating the fuck out of me...
Chi-Squared anomalies scare the shit out of me :tinfoil:
Would you guys laugh at me if I tried to make a disaster predicting function?
[t]http://noosphere.princeton.edu/images/images2/terror010911stz2.gif[/t]
If you want a great /x/ tier creepypasta just read about "global consciousness"
Anywho, I'm now using mt_srand (I read alot about how these functions work as well)
I've wanted the quotes to be the same if two people visit the site at the same time, and I've figured out how to use srand to allow the quotes to continue to be random, but be the same depending on the minute of the day.
Does srand affect rand() across all of php once its set? I don't see how it [I]isn't [/I]doing that in my function.
[editline]18th March 2014[/editline]
[QUOTE=01271;44273354]<?php
$quotes = array('quote', 'quote');
if (isset($nsfw) && $nsfw == true){
$nsfw_quotes = array('shit','fuck');
$quotes = array_merge($quotes, $nsfw_quotes);
}
echo $quotes[rand(0, count($quotes) - 1)];
?>[/QUOTE]
Oh... array_merge :rolleyes:
[editline]18th March 2014[/editline]
[QUOTE=CBastard;44275120]
[code]
session_start();
[/code]
What is the significance of using session_start() ?
[/quote]
Hey guys, i want to make a website for my freelance film and photography business, but i don't really have any experience. So i want to know, who are the best host sites? And do you know of any templates i can use, if i want a site like this: [url]http://paultrani.com/files/photographywebsite/[/url] ? I don't want to code myself, i just want an easy solution.
[QUOTE=chill_dude;44288353]Hey guys, i want to make a website for my freelance film and photography business, but i don't really have any experience. So i want to know, who are the best host sites? And do you know of any templates i can use, if i want a site like this: [url]http://paultrani.com/files/photographywebsite/[/url] ? I don't want to code myself, i just want an easy solution.[/QUOTE]
You want a fancy website for nothing/cheap. There might be an online website builder that can build websites like that but I don't know what the price would be
[QUOTE=djjkxbox360;44291189]You want a fancy website for nothing/cheap. There might be an online website builder that can build websites like that but I don't know what the price would be[/QUOTE]
When I was with them, LithiumHosting had a cool page builder. And they're pretty cheap and have a good reputation...
You could check them ([URL="http://lithiumhosting.com/hosting"]they have a free trial, down the offers[/URL]).
i'd suggest just looking at shopify or wordpress with nice themes if you want something thats super low maintenance
[QUOTE=chill_dude;44288353]Hey guys, i want to make a website for my freelance film and photography business, but i don't really have any experience. (...) I don't want to code myself, i just want an easy solution.[/QUOTE]
PM me, I'm so bored waiting for my internship to start that I'll do it without costs.
[editline]20th March 2014[/editline]
I say PM me because I need some sleep. Send me some details too btw.
Hey dudes!
I'm trying to resize a canvas in JavaScript and then write something on it (after it has been resized). I'm still not 100% sure what I'm going to be displaying on the canvas - for now it is just text but it could end up being shapes or other cool things.
Essentially, [URL="http://jsfiddle.net/nQbjr/2/"]this[/URL] is the root of my problem.
I want to resize that canvas when you click on it, and have it show text after the resize.
Does anyone know how I could do this? Is a canvas not the right element for this? Should I just use a div?
[editline]20th March 2014[/editline]
Also - the problem I was having when trying to do this with a div is that I couldn't get the Div's width to change through JavaScript!
If you take the example above and just change the <canvas> tag to a <div> tag and remove the canvas-specific javascript, then the example doesn't work at all. Just the background color changes!
For something as graphically simple as that, you should just use a div.
[url]http://jsfiddle.net/nQbjr/3/[/url]
I think I fixed it for you. You'll probably want to customize the text in the css
[QUOTE=djjkxbox360;44301901]For something as graphically simple as that, you should just use a div.
[url]http://jsfiddle.net/nQbjr/3/[/url]
I think I fixed it for you. You'll probably want to customize the text in the css[/QUOTE]
Sweet thank you!
I guess I was missing the inline-block on the div.
I also just added a timer to the text change so that it only appears when the width animation is done:
[CODE]
setInterval( function() { $warningbox.text('hello'); }, 600);
[/CODE]
[editline]20th March 2014[/editline]
Is there any better way of doing this timer other than like this?:
[CODE]
var timer = setInterval(function(){$warningbox.text('hello');},600);
setInterval(function(){window.clearInterval(timer);},600);
[/CODE]
I've never worked with timers in JavaScript before. It just seems kind of silly.
[QUOTE=Poo Monst3r;44302824]
Is there any better way of doing this timer other than like this?:
[CODE]
var timer = setInterval(function(){$warningbox.text('hello');},600);
setInterval(function(){window.clearInterval(timer);},600);
[/CODE]
I've never worked with timers in JavaScript before. It just seems kind of silly.[/QUOTE]
Intervals (AFAIK) are for something that happens more than once.
If I understood what you're trying to do, you could use jQuery's .delay()
or setTimeout, but since you're using jQuery anyway, you might as well use the delay function
Hello,
I have been modifying a loading screen for my server and it has been giving me problems.
Upon opening the link, the loading screen loads for a while, and then crashes.
This prevents users from seeing the loading screen at all when joining.
[URL="http://loading.samg381.com"]Here's the loading screen.[/URL]
I have absolutely no clue what the issue is.
Chrome and the gmod browser just simply crash.
Here is the javascript that is causing the issue.
[CODE]
/*-----YOUTUBE PLAYER-----*/
/* List of Youtube videos. One will be picked at random upon page load and played. */
/* You must use the embed link of each video */
/* If you just want a single video to be played, only use a single link. */
var tracks = new Array(
);
var playerEnabled = false; // Youtube player enabled?
var showVideo = false; // Show video?
/*-----RANDOM HINTS-----*/
/* List of hints to be cycled randomly. */
var hints = new Array(
);
var hintsEnabled = true;
/*-----SLIDESHOW----*/
/* List of images to put in slideshow. ALL IMAGES GO HERE!!!!*/
var imagepaths = new Array(
"http://loading.samg381.com/images/loading/1.jpg",
"http://loading.samg381.com/images/loading/2.jpg",
"http://loading.samg381.com/images/loading/3.jpg",
"http://loading.samg381.com/images/loading/4.jpg",
"http://loading.samg381.com/images/loading/5.jpg",
"http://loading.samg381.com/images/loading/6.jpg",
"http://loading.samg381.com/images/loading/7.jpg",
"http://loading.samg381.com/images/loading/8.jpg",
"http://loading.samg381.com/images/loading/9.jpg",
"http://loading.samg381.com/images/loading/10.jpg",
"http://loading.samg381.com/images/loading/11.jpg",
"http://loading.samg381.com/images/loading/12.jpg",
"http://loading.samg381.com/images/loading/13.jpg",
"http://loading.samg381.com/images/loading/14.jpg",
"http://loading.samg381.com/images/loading/15.jpg"
);
var slideShowEnabled = true;
/*--------DO NOT EDIT ANYTHING BENEATH THIS LINE, UNLESS YOU KNOW WHAT YOU'RE DOING--------*/
var thisIndex = 0;
var lastIndex = 0;
var curImage = 0;
$(document).ready(function() {
if(slideShowEnabled){
$("#background").hide().attr("src", imagepaths[curImage]).fadeIn(3000);
curImage++;
} else {$("#background").hide();}
if(!showVideo) {
$("#vid").css("width", "0.01%");
$("#vid").css("height", "0.01%");
$("#vid").css("-webkit-box-shadow", "0px 0px 0px 0px rgba(0, 0, 0, 1)");
$("#vid").css("box-shadow", "0px 0px 0px 0px rgba(0, 0, 0, 1)");
}
if(hintsEnabled) {
thisIndex = Math.floor(Math.random()*hints.length);
lastIndex = thisIndex;
$("#hint").hide().html(hints[thisIndex]).fadeIn(3000);
}
if(playerEnabled) {
$("#video").attr("src", tracks[Math.floor(Math.random()*tracks.length)])
}
});
if(hintsEnabled) {
setInterval(function(){
while(thisIndex == lastIndex) {
thisIndex = Math.floor(Math.random()*hints.length);
}
$("#hint").fadeOut(1000, function() {
$("#hint").html(hints[thisIndex]).fadeIn(3000);
});
lastIndex = thisIndex;
}, 10000);
}
if(slideShowEnabled) {
setInterval(function(){
if(curImage >= imagepaths.length) {
curImage = 0;
}
$("#background").hide().attr("src", imagepaths[curImage]).fadeIn(3000);
curImage++;
}, 10000);
}
$(function() {
$(".meter > span").each(function() {
$(this)
.data("origWidth", $(this).width())
.width(0)
.animate({
width: $(this).data("origWidth")
}, 1200);
});
});
/*
// Called when a file starts downloading. The filename includes the entire path of the file;
// for example "materials/models/bobsModels/car.mdl".
function DownloadingFile( fileName ) {
$("#loadingtext").hide().text("Downloading " + fileName).fadeIn(300);
}
// Called when something happens. This might be "Initialising Game Data", "Sending Client Info", etc.
function SetStatusChanged( status ) {
$("#loadingtext").hide().text(status).fadeIn(300);
}
*/
[/CODE]
Any and all help is appreciated.
You have hints enabled but you don't have any hints, so when it gets to this part, it loops forever:
[code]
while(thisIndex == lastIndex) {
thisIndex = Math.floor(Math.random()*hints.length);
}
[/code]
Because hints.length = 0, Math.random() * hints.length will always be 0, so thisIndex always equals lastIndex. Either disable hints (set hintsEnabled to false), or add some hints in (at least two).
Thanks for the fast reply.
Doesn't seem to have fixed anything.
I tried to add two hints and also disable it.
I will be back tomorrow, I'm going to sleep.
[B]
EDIT:
[/B]Fixed it! deleted the code itself. Bingo, it works!
Trying to create a snippet in sublime text 2, but it won't work.
I even tried breaking it down to the simplest snippet, still not working. What's wrong?
[code]
<snippet>
<content>
<![CDATA[
<h1></h1>
<p></p>
]]>
</content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>elements</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.html</scope>
<description>Testing snippet</description>
</snippet>
[/code]
And it's saved in: [B]C:\Users\math8388\AppData\Roaming\Sublime Text 2\Packages\User[/B] as [B]elements.sublime-snippet[/B]
I'm working with a [URL="https://github.com/Serhioromano/bootstrap-calendar"]Twitter Bootstraps Calendar[/URL] that uses some strange form of embedded HTML programming language:
[CODE]
<% _.each(events, function(event) { %>
<div class = "box-<%= event['class'] %>">
</div>
<% }) %>
[/CODE]
Does anyone know what exactly this language is and where I can learn more on it? It looks like some form of embedded or inline JQuery...
[QUOTE=Poo Monst3r;44312208]I'm working with a [URL="https://github.com/Serhioromano/bootstrap-calendar"]Twitter Bootstraps Calendar[/URL] that uses some strange form of embedded HTML programming language:
[CODE]
<% _.each(events, function(event) { %>
<div class = "box-<%= event['class'] %>">
</div>
<% }) %>
[/CODE]
Does anyone know what exactly this language is and where I can learn more on it? It looks like some form of embedded or inline JQuery...[/QUOTE]
[quote]Bootstrap Calendar depends on jQuery and [i][url=http://underscorejs.org/]underscore.js[/url] is used as a template engine. [/i][/quote]
Well damn. I saw that but had no idea what it was.
This shit is confusing as hell, the syntax is all weird and everything is a function. Is this not just the JavaScript version of PHP?
I'll never be able to memoize this language...
[IMG]http://i59.tinypic.com/2ec0q3t.png[/IMG]
Its just a templating system to make ur life easier
[QUOTE=Poo Monst3r;44312379]Well damn. I saw that but had no idea what it was.
This shit is confusing as hell, the syntax is all weird and everything is a function. Is this not just the JavaScript version of PHP?
I'll never be able to memoize this language...
[IMG]http://i59.tinypic.com/2ec0q3t.png[/IMG][/QUOTE]
What you're showing there isn't confusing at all to me, so I wouldn't say underscore is the JS version of PHP.
[QUOTE=Poo Monst3r;44312379]Well damn. I saw that but had no idea what it was.
This shit is confusing as hell, the syntax is all weird and everything is a function. Is this not just the JavaScript version of PHP?[/QUOTE]
Why wouldn't everything be a function? It's completely understandable, much more so than PHP.
[url=https://gist.github.com/meowy/f341253bbd0a2285250e]I annotated the source code of memoize.[/url] Read it if you like.
It seems as I've come to the point where I don't have any motivation at all to work on my projects. I'm in a very bad position as I really need to get my projects done in order to put them on a CV or starting my own business. Whichever comes first.
I have heard that getting a partner to work with can be very motivational, but I can't seem to find anyone. I've been "stalking" people here on Facepunch and other communities aswell but it always ends up in that the one I'm looking at either is too inexperienced, or too experienced for me that I would just scare them away if contacted about it. Or they already have their full time job with great pay somewhere and would not waste his time working with me.
I would love to hire someone to work with if I had the money for it, but as I currently have a hard time managing my personal economy I can't pay anyone to work with me. If I ever come to the point where I'm able to hire someone, I would hire someone with skill and never, ever underpay the person.
My dream is to start my own business, with someone or by myself, but it seems impossible as I have no motivation when working by myself and can't seem to find someone that is willing or suitable. I've tried teaching people but they are either busy with school, losing interest or just gaming.
As [URL="http://facepunch.com/showthread.php?t=1378002&p=44307854&viewfull=1#post44307854"]Moofy stated[/URL] in another thread, and I agree fully since I find absolutely no pleasure by gaming. I love programming & sys-administration and that is what I want to work with in my life. It just feels like it's out reach at this point.
[B]So now I've decided to step out of the shadows and ask, is there [U]anyone[/U] here that's interested in working with me?[/B]
The lanuage I primarily know and work with is PHP. I would say that I'm good with programming, but I am actually a very talented sys-administrator. Although I know my way around PHP quite nicely, I feel like I have more things to learn about it.
I've been hosting, helping and maintaining communities for free for a very long time now. I've coded some simple open-source projects aswell. But I've come to the point where I cannot keep doing things for free anymore. I need to get my projects done so I can either start my own business, or put them on my CV. As I said earlier, my dream is to start a business, with someone or by myself. [U]So that's what I'm aiming for with the person I may end up working with[/U].
I don't know if this deserves its own thread or not, so I'll just post it here, hoping for something.
Instead of just PHP, maybe spread out and grasp some other languages?
For example, Ruby has [url=http://en.wikipedia.org/wiki/Chef_(software)]Chef[/url] and [url=http://en.wikipedia.org/wiki/Puppet_(software)]Puppet[/url], not to mention Rails. C#, C++, and Java are somewhat known for video games - while C++ and C could be used to make server software.
I think limiting yourself to just PHP is a shame - expand your views, and you might even learn a little bit about PHP in the mean time. I wouldn't mind working with you, but unfortunately, I don't write PHP; I'm solely a Ruby/C guy.
[QUOTE=Ac!dL3ak;44324090] I wouldn't mind working with you, but unfortunately, I don't write PHP; I'm solely a Ruby/C guy.[/QUOTE]
The same goes for me. I much prefer Ruby over PHP, and really suggest you to look into it, Svenskunganka.
This might be a stupid question, but is there any way to install [URL="http://twig.sensiolabs.org/doc/installation.html"]Twig [/URL]without shell (which is needed for git, composer, etc.)? I'd like to try it out on a shared hosting, and I don't think I can use it.
[QUOTE=Ac!dL3ak;44324090]Instead of just PHP, maybe spread out and grasp some other languages?
For example, Ruby has [url=http://en.wikipedia.org/wiki/Chef_(software)]Chef[/url] and [url=http://en.wikipedia.org/wiki/Puppet_(software)]Puppet[/url], not to mention Rails. C#, C++, and Java are somewhat known for video games - while C++ and C could be used to make server software.
I think limiting yourself to just PHP is a shame - expand your views, and you might even learn a little bit about PHP in the mean time. I wouldn't mind working with you, but unfortunately, [B][U]I don't write PHP; I'm solely a Ruby/C guy.[/U][/B][/QUOTE]
Since you're from the UK, do you get any work for Ruby?
Just wondering because I hardly see jobs posted for ruby. Around where I live, anyway.
[QUOTE=Coment;44325060]This might be a stupid question, but is there any way to install [URL="http://twig.sensiolabs.org/doc/installation.html"]Twig [/URL]without shell (which is needed for git, composer, etc.)? I'd like to try it out on a shared hosting, and I don't think I can use it.[/QUOTE]
You can [URL="https://github.com/fabpot/Twig/tags"]download the tarball[/URL].
let me take this underscore and give it some time...
i guess im always open to new things...
JS
How can I check that at least one checkbox is ticked in each group of checkboxes on a page?
Sorry, you need to Log In to post a reply to this thread.