function fetchImage(url) {
return fetch(url)
.then(checkStatus)
.then( res => res.json() )
.catch( error => console.log('An Error Ocurred!', error) )
}
This code demonstrates how a promise can be use to fetch images from Lorem Picsum
Used in:
Simple Image Generator
Language:
JavaScript (ES6)
main function:
fetches the images using its URL. If the URL exists, then it will proceed to fetch it's JSON data. Throws an error if it does not.
def clean_data(x):
if isinstance(x, list):
return [str.lower(i.replace(" ", "")) for i in x]
else:
if isinstance(x, str):
return str.lower(x.replace(" ", ""))
This code demonstrates the cleaning process of data in a dataset.
Used in:
Anime Recommender System
Language:
Python
main function:
Iterates through each cell in a dataset, removing any whitespace present. Top condition demonstrates removing whitespace from a list, and the bottom demonstrates removing from a string.
public function __construct($config)
{
$dsn = 'mysql:' . http_build_query($config, '', ';');
$username = $_ENV['DB_USER'];
$password = $_ENV['DB_PASS'];
$this->connection = new PDO($dsn, $username, $password, [
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]);
}
This code demonstrates how a database is connected to the project.
Used in:
Netmatters Contact Page
Language:
PHP
main function:
public function index()
{
$admin = User::first();
$new_companies = DB::table('companies')->limit(9)->orderBy('id', 'desc')->get();
$new_employees = DB::table('companies')
->join('employees', 'employees.company_id', '=', 'companies.id')
->limit(9)->orderBy('id', 'desc')->select('employees.*', 'companies.name', 'companies.logo')->get();
return view('admin.index',[
'admin' => $admin,
'companies' => $new_companies,
'employees' => $new_employees
]);
}
This code demonstrates querying a database to receive data from it.
Used in:
Company Admin Panel
Language:
Laravel
main function:
the new companies and employees variables store the 10 latest companies and employees, which are sent to the index view, where they can be displayed on the screen