Skip to content

Instantly share code, notes, and snippets.

View Atinux's full-sized avatar

Sébastien Chopin Atinux

View GitHub Profile
@Atinux
Atinux / last-digit-ean13.js
Last active November 29, 2019 18:07
Get last digit of an EAN/GTIN 13 in JavaScript
function getLastEan13Digit(ean) {
if (!ean || ean.length !== 12) throw new Error('Invalid EAN 13, should have 12 digits')
const multiply = [1, 3]
let total = 0
ean.split('').forEach((letter, index) => {
total += parseInt(letter, 10) * multiply[index % 2]
})
@Atinux
Atinux / forEach.proto.js
Last active October 4, 2017 09:25
Simple prototype of forEach
Array.prototype.forEach = function (callback) {
// this represents our array
for (let index = 0; index < this.length; i++) {
// We call the callback for each entry
callback(this[index], index, this)
}
}
@Atinux
Atinux / forEach.js
Created October 3, 2017 13:13
forEach example with async/await (fail)
const waitFor = (ms) => new Promise((resolve) => setTimeout(resolve, (ms || 0)))
[1, 2, 3].forEach(async (num) => {
await waitFor(50)
console.log(num)
})
console.log('Done')
@Atinux
Atinux / index.vue
Created July 4, 2017 10:25
Dynamic image nuxt
<template>
<div>
<h1>Welcome!</h1>
<nuxt-link to="/about">About page</nuxt-link>
<img :src="flagUrl"/>
<button @click="nextFlag">Next flag</button>
</div>
</template>
<script>
<html lang="en"><head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAIAAAD8GO2jAAADjklEQVR4AWI08P/HQEvAQrxSQKvlECfLFYXx75xCY2qmh89GbNvOMjb3v9jOOlxnFWxj206ebQ3b7q6q+z1rNagu8/zvPSZACAABpeUAA0miMgU7SA7JjCraFGwZwECOwvL75dWjsKgWBKtx0jvWo+vkBAFbACCkByMP6nMn48+AVgXB2fzSCwsv22/lMGlUhmJ0AE7BH8dyUUDbUEgN6RzJRSeaPxhdRYR0Inel+7Hd5lBiFpkMAxACc0394//9C4voFHDiAAGLpuOXebdfdHfctgwJKaZRLRKy6ItrSis6RBnVBgGtbHyKTEmJHQoEXoBCE5BCrDeA2ogMUIGDAKEBDEhUqwgMqBYDjW4DQzmuffVdqff42/ZQYYqVcMXGZsMPyCsH3lyJSetxvEaxAQXdjR1HjfwCdIS7lo2DZke26Qe+MXO12OWkGT0O6oE7vMGkMnkYw4aN1KQgMKExhXqswfiov4+a7MQ11XPnbr/5qpKlgACAAQj94Lu271bN9DUecQasIZlNzG72llRAAKJiAi+/BSHrSFjRvQhg3DEKEqJh08tsmLTx597+f6enr4cc2Zpk57pihfX24dW7RHcOLLUbJYhJSl0ErQCI9BVXH/XrO97QasuvQQSiECa0BrQCIIJp6X9T/r8QG6L71WYSqCoIIGo2BZDUBnS/D9EA9Nun1iYvbM0MFExIDQRoKFatc1Z6zrm5uWeObJotq0BGV9FuQBWq5a4Fw3PPz848rZHstZSuA5FWAFSMP2nOppOOGpl6qh9PCSg0IFyHKjSQy
@Atinux
Atinux / proxy-cheat.js
Created December 2, 2013 22:01
Cheat Candy Crush via node.js proxy
var http = require('http'),
request = require('request'),
port = 8000;
http.createServer(function (req, res) {
console.log('Proxying url ['+req.url+']');
if (req.url.indexOf('http://candycrush.king.com/api') !== -1 && req.method === 'GET') {
request(req.url, function (err, response, body) {
for (var header in response.headers) {
res.setHeader(header, response.headers[header]);
@Atinux
Atinux / analysis.yaml
Created November 21, 2013 15:39 — forked from alexbrasetvik/analysis.yaml
Standard tokenization, but without the lowercasing and stopword removal.
text: Je suis une petite hirondelle qui adore sautiller dans l'herbe chanté bébé à l'@email !
analyzer:
standard:
type: standard
simple:
type: simple
stop:
type: stop
snowball:
@Atinux
Atinux / console-socket.js
Last active December 15, 2015 19:19
Envoyer des sockets depuis la console node.js
var http = require('http');
var fs = require('fs');
var io = require('socket.io');
// La page HTML
var html = '<meta charset="UTF-8">'
+ '<script type="text/javascript" src="/socket.io/socket.io.js"></script>'
+ '<script type="text/javascript">'
+ 'var socket = io.connect();'
+ 'socket.on("serverConsole", function (message) {'
@Atinux
Atinux / countdown.js
Created January 17, 2013 00:57
Super countdown with jQuery.
var countDown = function (endDate, el) {
el = el || $('body');
var leadingZero = function (nb) {
return (nb < 10) ? "0" + nb : + nb;
};
var updateTimer = function (seconds) {
var days = Math.floor(seconds / 86400);
seconds -= days * 86400;
var hours = Math.floor(seconds / 3600);
seconds -= hours * (3600);
@Atinux
Atinux / app.js
Created December 27, 2011 00:33
Backbone JS infinite data with Node JS and Express JS
/*
** Client side - /public/src/app.js
*/
var myApp = {
// Collections
Collections: {
list: Backbone.Collection.extend()
},
// Views