Skip to content

Instantly share code, notes, and snippets.

View debonx's full-sized avatar
🍕
Food processing

Emanuele De Boni debonx

🍕
Food processing
View GitHub Profile
@debonx
debonx / luhns-algorithm.c
Last active November 28, 2020 11:02
Luhn's algorithm implementation for credit card sequence validation.
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_card_length(long card)
{
int length = 0;
while (card > 0)
{
@debonx
debonx / media-queries.scss
Created April 25, 2020 15:27 — forked from chrisjlee/media-queries.scss
All Media Queries breakpoints
@media (min-width:320px) { /* smartphones, portrait iPhone, portrait 480x320 phones (Android) */ }
@media (min-width:480px) { /* smartphones, Android phones, landscape iPhone */ }
@media (min-width:600px) { /* portrait tablets, portrait iPad, e-readers (Nook/Kindle), landscape 800x480 phones (Android) */ }
@media (min-width:801px) { /* tablet, landscape iPad, lo-res laptops ands desktops */ }
@media (min-width:1025px) { /* big landscape tablets, laptops, and desktops */ }
@media (min-width:1281px) { /* hi-res laptops and desktops */ }
@debonx
debonx / missing-integers.js
Last active September 30, 2022 09:36
JavaScript: Simple function to find positive missing integers in Array of numbers.
/* Write a function solution(A); that, given an array A of N integers, returns the smallest positive integer (greater than 0) that does not occur in A.
For example, given A = [1, 3, 6, 4, 1, 2], the function should return 5.
Given A = [1, 2, 3], the function should return 4.
Given A = [−1, −3], the function should return 1.
Write an efficient algorithm for the following assumptions:
N is an integer within the range [1..100,000];
each element of array A is an integer within the range [−1,000,000..1,000,000]. */
const A = [-1, -4];
@debonx
debonx / database.sql
Created January 31, 2020 15:44
SQL: Create, insert, Alter, Update, Delete and Select.
CREATE TABLE friends (
id INTEGER,
name TEXT,
birthday DATE
);
INSERT INTO friends (id, name, birthday)
VALUES
(1, 'Jane Doe', '1990-05-30'),
(2, 'Richard Stallman', '1953-03-16'),
@debonx
debonx / factorial.js
Created January 26, 2020 10:04
Node, Mocha: Simple factorial test suite with Mocha and Node assertion methods.
const Calculate = {
factorial(number) {
if(number === 0) {
return 1;
}
for(let i = number - 1; i >= 1; i--) {
number *= i;
}
return number;
}
@debonx
debonx / rooster.js
Last active January 26, 2020 10:05
Node, Mocha: Simple test suite for Rooster object with Mocha and Node asserts methods. (https://mochajs.org, https://nodejs.org/api/assert.html).
// Define a rooster
Rooster = {};
// Return a morning rooster call
Rooster.announceDawn = () => {
return 'moo!';
}
// Return hour as string
// Throws Error if hour is not between 0 and 23 inclusive
@debonx
debonx / node-filesystem.js
Created January 19, 2020 19:22
Node: Filesystem core module.
const fs = require('fs');
let readDataCallback = (err, data) => {
if (err) {
console.log(`Something went wrong: ${err}`);
} else {
console.log(`Provided file contained: ${data}`);
}
};
fs.readFile('./finalFile.txt', 'utf-8', readDataCallback);
@debonx
debonx / node-async-error.js
Created January 19, 2020 19:20
Node: Error handling, async Vs. error-first.
const api = require('./node-error-api.js');
// Not an error-first callback
let callbackFunc = (data) => {
console.log(`Something went right. Data: ${data}\n`);
};
try {
api.naiveErrorProneAsyncFunction('problematic input', callbackFunc);
} catch(err) {
@debonx
debonx / node-input-output-game-1.js
Created January 19, 2020 19:11
Node: User Input / Output game.
let secretValue = Math.floor(1+Math.random()*10).toString();
let numbers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'];
module.exports = {
testNumber: (input) => {
if (input === 'quit') {
process.stdout.write('Ok. Bye!\n')
process.exit();
}
@debonx
debonx / node-events.js
Created January 19, 2020 19:08
Node: Event-Driven Architecture, exploring .EventEmitter() method.
// Require core events
let events = require('events');
// Create Event Callback
let listenerCallback = (data) => {
console.log('Celebrate ' + data);
}
// Init EventEmitter method
let myEmitter = new events.EventEmitter();