Skip to content

Instantly share code, notes, and snippets.

View MSerj's full-sized avatar

Mitu Sergiu MSerj

View GitHub Profile
@MSerj
MSerj / js_features.js
Last active March 16, 2020 08:08
Some js feature
// conditional add prop
const user = { id: 100, name: 'Howard Moon' }
const password = 'Password!'
const userWithPassword = {
...user,
id: 100,
...(password && { password })
}
userWithPassword //=> { id: 100, name: 'Howard Moon', password: 'Password!' }
@MSerj
MSerj / .htaccess
Last active May 22, 2018 07:30
Apache react spa htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png|svg|otf|ttf|woff|woff2|eot|mp4|mpeg|avi)$ [NC]
RewriteRule . /index.html [L]
#OR
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
@MSerj
MSerj / nFormatter.js
Last active November 16, 2023 09:40
nFormatter (number format with k and m)
function nFormatter(num, digits) {
const si = [
{ value: 1, symbol: "" },
{ value: 1E3, symbol: "k" },
{ value: 1E6, symbol: "M" },
{ value: 1E9, symbol: "G" },
{ value: 1E12, symbol: "T" },
{ value: 1E15, symbol: "P" },
{ value: 1E18, symbol: "E" }
];
@MSerj
MSerj / formatnumber.js
Created April 13, 2018 07:41
format number with spaces
function numberWithSpaces(nr) {
return nr.toString().replace(/\B(?=(\d{3})+(?!\d))/g, " ");
}
@MSerj
MSerj / countdown.html
Last active April 11, 2018 11:46
Timer countdown
<div class="countdown-block">
<div class="text">Don't miss it! Token sale ends in:</div>
<div class="countdown-wrap">
<div class="countdown" id="countdown">
<span id="days">30</span>
<span id="hours">21</span>
<span id="minutes">15</span>
<span id="seconds">00</span>
</div>
<div class="countdown-text">
@MSerj
MSerj / header.css
Created February 8, 2018 14:32
FIX jumping position fixed in google chrome
.header {
position: fixed;
-webkit-transform: translateZ(0); //use this FIX
backface-visibility: hidden; //or this FIX
}
//BOTH works
@MSerj
MSerj / package.json
Last active February 5, 2018 08:49
npm scripts examples
{
"scripts": {
"sass": "node-sass --source-map=true -w ./src/scss/style.scss -o ./dist/server/public/css/ --style compressed",
"prefix": "postcss -u autoprefixer --autoprefixer.browsers 'ie 10, android 4, opera 12.1, > 2%' -r ./dist/server/public/css/style.css",
"babel": "babel ./src/ -d ./dist/ -w",
"webpack": "webpack -w",
"server": "nodemon ./dist/server/server.js",
"sync": "browser-sync start --directory --server --files '*.css, *.js, *.html'",
},
}
@MSerj
MSerj / multiple_swiper.js
Last active July 27, 2022 16:07
Multiple Instances of Swiper on Same page
if ($('.swiper-container').length > 0) { //some-slider-wrap-in
let swiperInstances = [];
$(".swiper-container").each(function(index, element){ //some-slider-wrap-in
const $this = $(this);
$this.addClass("instance-" + index); //instance need to be unique (ex: some-slider)
$this.parent().find(".swiper-pagination").addClass("pagination-" + index);
$this.parent().find(".swiper-button-prev").addClass("prev-" + index); //prev must be unique (ex: some-slider-prev)
$this.parent().find(".swiper-button-next").addClass("next-" + index); //next must be unique (ex: some-slider-next)
swiperInstances[index] = new Swiper(".instance-" + index, { //instance need to be unique (ex: some-slider)
// your settings ...
@MSerj
MSerj / get_number_from_string.js
Created December 20, 2017 16:59
JavaScript get number from string
var txt = "#div-name-1234-characteristic:561613213213";
var numb = txt.match(/\d/g);
numb = numb.join("");
alert (numb);
//result
1234561613213213
@MSerj
MSerj / get_class_of_element.js
Created December 20, 2017 16:57
get class list of element
//You can use document.getElementById('divId').className.split(/\s+/); to get you an array of class names.
//Then you can iterate and find the one you want.
var classList = document.getElementById('divId').className.split(/\s+/);
for (var i = 0; i < classList.length; i++) {
if (classList[i] === 'someClass') {
//do something
}
}
//jQuery does not really help you here...