Random seed is a method of initializing random number generators using an initial seed value. Random generators with the same seed will output the same pseudo-random results. I found this method to be particularly useful when developing a game I'm working on, which has a random 'Daily Challenge'. In this case, random seed can be useful to select a random game using the current date as a seed. Seed random is one of a few features that is present in most major programming languages but is not available out-of-the-box in JavaScript. It can be incredibly useful in a wide array
Let's say you want to swap the values of two integer variables, a, and b. Simply setting a equal to b and then b equal to a does not work, since a and b would just end up both equaling the initial value of b. So, typically, you'd create another variable - let's call it c - and set that variable to the value of a, and then do something like this. This is very simple, but the extra variable is not actually necessary. Note that some programming languages, for example Python, provide the ability to swap two variables in
Rate limiting is the process of preventing repeated requests to a server in effort to remove spam requests. Typically, a limit is set, such as 200 requests to the server per minute, and any IP address that exceeds that limit will be blocked from making requests for a set period of time. Rate slowing down is the process of slowing down server responses to an IP that has been sending too many requests. For example, the slow down limit could be set to 200 requests per minute, and an extra 2.5 seconds more response time could be added for each
Have you ever wondered how your computer calculates certain mathematical functions, like division, or trigonometric functions like sine or cosine? Well, for some of these mathematical functions, there exist useful formulas to calculate very accurate results pretty easily. I've written programs to implement these two computations in three major scripting languages: Python, JavaScript, and Perl. These programs do not include any built-in trig functions or other utilities except the use of the in-built π constant in some cases. All code is CC0 licensed. The approach I used creates a generalized function called computeSeries which takes in x as the number
The HTML5 Gamepad API is one of the more exciting HTML5 APIs in my opinion. The API allows browser games and sites to take input from real game controllers connected to the user's machine. Hundreds of game controllers are supported, both wireless and wired, including Xbox One controllers, PS4 controllers, and more. In this article, I'll provide a full explanation of the many features that the Gamepad API offers, with examples in JavaScript. Information on browser support, gamepad button codes, taking input from the gamepad sticks, and more is included.
Cronjobs are tasks that can be run periodically, such as every five minutes, or every day at midnight, or even every Friday at noon. Cronjobs have a number of different use cases, and are widely used in many notable codebases. Many hosting servers have existing ways to set up cronjobs, but if you don't have that capability, you may want to go for a different solution. I'll explain how you would go about creating cronjobs in Python, in which a Python function, program, or system command can be run periodically, whether that be every day, every few minutes, or even
The Sierpinski triangle is a famous mathematical figure which presents an interesting computer science problem: how to go about generating it. In this article I'll explain one method of generating the Sierpinski triangle recursively, with an implementation written in Vanilla JavaScript using HTML5 canvas.
I recently worked on an open source project called Jupiter, an online AI written in JavaScript to beat the popular online game 2048. In this article, I'll be analyzing the performance and speed of Jupiter's algorithm with empirical data, and note potential improvements made to the algorithm and its JavaScript implementation on the web. I ran 50 trial games with the AI at 200 simulations per move in about 34 minutes (avg. 40.8s/trial), storing data after every move.
Today I'm proud to release my online 2048 AI, Jupiter. Jupiter uses a machine learning method called the Monte Carlo Tree Search (MCTS) algorithm. I've released an article detailing the algorithm and implementation used in Jupiter: Using the Monte Carlo Tree Search (MCTS) Algorithm in an AI to Beat 2048 (and other games). Jupiter (formerly known as Jacob) started as a small AI project in January 2018. I got the idea of using Monte Carlo simulations and search trees as a method to play 2048 from this StackOverflow answer.
I recently worked on an open source project called Jupiter, an online AI to beat the popular online game 2048. In writing this AI, I decided to use a machine learning method called the Monte Carlo Tree Search (MCTS) algorithm. Monte Carlo algorithms like the one used in Jupiter have been used in several notable AIs, including DeepMind's AlphaGo, which famously beat the Go world champion in May 2017. In this article, I'll explain: How and why the Monte Carlo method works; When and where Monte Carlo algorithms can be useful; How I used the Monte Carlo method in an
I recently spent a few hours refactoring some of the backend code on this site. In changing the backend, I wanted to make sure the refactored code worked the same way as my old code. To do this, I wrote a unit test in Python that sent a request to every URL on my site running the old backend code and the corresponding URL with my local server running the new code, to make sure they worked exactly the same.
Discord bots can be useful in doing a variety of things like playing music in a voice chat, or sending automated announcements when a Youtuber releases a new video. I'm active on several Discord servers myself and have always wanted to build my own Discord bot. After building, deploying, and using my own bot for over a month now, I've written this article as a starting point in building a basic bot and moving from there. We'll be building a bot that does something pretty simple: solves math equations. Users will be able to send a message on any channel
Custom scrollbars on the web can make a site or design stand out. They can help in portraying key design aspects of a site, whether that be a specific color or a particular style. For example, the scrollbar at Outlook.com's web app portrays a very minimalist style. CSS-Tricks' scrollbar shows their signature orange and pink look. In this post, we'll be building a minimalist custom scrollbar, similar to that on the Outlook.com web app.
Due to lockdown and quarantine in numerous countries, this year's AP tests were moved to an online platform created by College Board, the creator of the AP program and other tests such as the SAT. In most online AP tests this year, students were given 1-2 questions on the exam web app, and were given the option to submit either a photo of their work, a supported text file (ex: .txt, .docx), or copy and paste written text.
Today, I am proud to release my latest web app and project: Coronavirus (COVID-19) Live Monitor, your hub for news and information on the Coronavirus outbreak. The code can be found on the GitHub repo. Go check it out!
Global variables can cause serious problems and bugs in large-scale projects and web apps. IIFE's solve this problem by wrapping code in an immediately invoked function, so that no global variables are created, but the code still runs without having to be directly called. For smaller sites and scripts, I would personally simply recommend actively trying to use IIFE's whenever possible, and limiting global code. I personally do use global variables in some basic sites for brevity, but it's important to have a clear understanding of what your code's global scope looks like and what sorts of unexpected problems could
I just recently added a fun little feature on my website: a progress bar when reading blog posts. The bar would show how far users have progressed in reading a post, from 0% at the beginning to when a user finishes reading at 100%. This little feature has become particularly popular among other blogs and Wordpress themes in recent years.
CSS variables have been around for quite some time now, but are nevertheless extremely useful. The value of a variable can be just about anything, from pixel values to colors to linear-gradients. You can use a variable almost anywhere by wrapping it in a var function.
In general, normal JavaScript allows for code that is badly written and includes bad syntax. But, use strict solves this problem. Introduced in ES5, the use strict directive provides a way to tell the interpreter to turn badly written JavaScript into errors.
Today I am proud to release my latest project -- a website and the first ever DEV bot (as far as I know), called Daily Developer Jokes. The Daily Developer Jokes bot will post programmer humor and jokes every day at 8:00 AM (EST).
LOLCODE is an esoteric programming language, a type of programming language which is defined by the Esolang Wiki as follows: an esoteric programming language is a computer programming language designed to experiment with weird ideas, to be hard to program in, or as a joke, rather than for practical use.
A list of three modern CSS features explained in ~2 minutes reading time. Features include: CSS clip paths, CSS blend modes, and CSS filters.
The developer world is changing quickly. New tech is quickly rendering old languages and frameworks useless, and the hype for new stuff such as WebAssembly, AI, and cryptocurrency is growing quickly. More developers are emerging faster than ever, and this decade could mark the end of an era in programming and the start of a new one.
JavaScript is a weird language. It's an object-oriented language, but for many years it never had classes. It was built for the browser, but now it can also run on a server and work with the filesystem. Over the years I've seen some pretty peculiar and equally pretty funny things, that will only work with JavaScript. Here are 5 of them.
I have used all three operating systems in my lifetime. When I used Windows it felt too bloated and I missed Bash, my Linux experience was really positive but too many apps didn't support the platform, and so I am sticking with MacOS for now. Every developer's needs are different depending on what they are using their machine for. What OS are you using and why?
As your site grows with more pages and features, your CSS can quickly become confusing. BEM is a way to help mitigate that confusion.
The flipping card animation is a quick way to make your site stand out as something modern. With newer CSS features such as the perspective property, we can make this animation pretty quickly and easily, yet maintain its eye-catching effect.
Who are some people whose posts on DEV you particularly enjoy?
It seems like almost every other click on the internet ends up in an error 404 page. So, I've built an automated program to find broken links.
50 years ago, the first ever message was sent using the Internet. Here's a brief history of what's changed since then.