Skip to content

Instantly share code, notes, and snippets.

Avatar
🍕
Food processing

huraji huraji

🍕
Food processing
View GitHub Profile
@huraji
huraji / luhns-algorithm.c
Last active Nov 28, 2020
Luhn's algorithm implementation for credit card sequence validation.
View luhns-algorithm.c
#include <cs50.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int get_card_length(long card)
{
int length = 0;
while (card > 0)
{
@huraji
huraji / media-queries.scss
Created Apr 25, 2020 — forked from chrisjlee/media-queries.scss
All Media Queries breakpoints
View media-queries.scss
@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 */ }
@huraji
huraji / missing-integers.js
Last active Feb 16, 2020
JavaScript: Simple function to find positive missing integers in Array of numbers.
View missing-integers.js
/* 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];
@huraji
huraji / database.sql
Created Jan 31, 2020
SQL: Create, insert, Alter, Update, Delete and Select.
View database.sql
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'),
@huraji
huraji / factorial.js
Created Jan 26, 2020
Node, Mocha: Simple factorial test suite with Mocha and Node assertion methods.
View factorial.js
const Calculate = {
factorial(number) {
if(number === 0) {
return 1;
}
for(let i = number - 1; i >= 1; i--) {
number *= i;
}
return number;
}
@huraji
huraji / rooster.js
Last active Jan 26, 2020
Node, Mocha: Simple test suite for Rooster object with Mocha and Node asserts methods. (https://mochajs.org, https://nodejs.org/api/assert.html).
View rooster.js
// 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
@huraji
huraji / node-filesystem.js
Created Jan 19, 2020
Node: Filesystem core module.
View node-filesystem.js
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);
@huraji
huraji / node-async-error.js
Created Jan 19, 2020
Node: Error handling, async Vs. error-first.
View node-async-error.js
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) {
@huraji
huraji / node-input-output-game-1.js
Created Jan 19, 2020
Node: User Input / Output game.
View node-input-output-game-1.js
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();
}
@huraji
huraji / node-events.js
Created Jan 19, 2020
Node: Event-Driven Architecture, exploring .EventEmitter() method.
View node-events.js
// 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();