Skip to content

Instantly share code, notes, and snippets.

View Margino's full-sized avatar
:octocat:
learning…

Alex Margino

:octocat:
learning…
  • Saint-Petersburg, Russia
View GitHub Profile
@Margino
Margino / randomNumber.js
Created August 30, 2022 08:55
Getting a random number between two values
const getRandomInt = (min = 0, max = 1000) => {
const random = (Math.random() * (max + 1 - min)) + min
return Math.floor(random)
}
@Margino
Margino / gist:57bb6dbfbe0ef3b632b78f9003ae8cb1
Created April 25, 2020 17:17 — forked from jonathanmoore/gist:2640302
Get the share counts from various APIs

Share Counts

I have always struggled with getting all the various share buttons from Facebook, Twitter, Google Plus, Pinterest, etc to align correctly and to not look like a tacky explosion of buttons. Seeing a number of sites rolling their own share buttons with counts, for example The Next Web I decided to look into the various APIs on how to simply return the share count.

If you want to roll up all of these into a single jQuery plugin check out Sharrre

Many of these API calls and methods are undocumented, so anticipate that they will change in the future. Also, if you are planning on rolling these out across a site I would recommend creating a simple endpoint that periodically caches results from all of the APIs so that you are not overloading the services will requests.

Twitter

@Margino
Margino / gulpfile.js
Created April 25, 2020 17:05
Версирование css и js
// gulp-rev 1) добавляем хэш в имя файла, прописываем их в manifest
// gulp-rev-collector переименовываем ссылки на хэшированные файлы. 1) указываем файлы в которых нужно изменить ссылки 2) указываем путь к манифестам
// gul-rev-outdated удаляем старые хэшированные файлы, для этого 1) устанавливаем кучу плагинов: npm i gulp-util rimraf gulp-rev-outdated path through2 2) добавляем функцию cleaner
const rev = require('gulp-rev');
const revCollector = require('gulp-rev-collector');
const gutil = require('gulp-util');
const rimraf = require('rimraf');
const revOutdated = require('gulp-rev-outdated');
@Margino
Margino / prefers-color-scheme.css
Created October 26, 2018 13:51
Adopt a dark appearance in addition to the standard light appearance (css, js)
// css
/* Text and background color for dark mode */
@media (prefers-color-scheme: dark) {
body {
color: #ddd;
background-color: #222;
}
}
// The prefers-color-scheme query supports three values: dark, light, and no-preference
@Margino
Margino / performance.mark
Created September 6, 2018 07:45
Measuring the performance of web pages
performance.mark('start');
// some code here
performance.mark('end');
performance.measure(‘_Label_’, 'start', 'end');
console.log(performance.getEntriesByType('measure'));
@Margino
Margino / iterator
Created September 2, 2018 12:59
Function that returns each value of the array when called, one element at a time
function returnIterator(arr) {
let i = 0;
function inner() {
const element = arr[i];
i++;
return element;
}
return inner;
}
@Margino
Margino / Gulp ssh
Last active July 1, 2018 14:29
Config for ssh deploy
// https://www.npmjs.com/package/gulp-rsync
// npm i -D gulp-rsync
const rsync = require('gulp-rsync');
gulp.task('deploy', function() {
return gulp.src('prodaction/**')
.pipe(rsync({
root: 'prodaction/',
hostname: 'name@name…tech',
function debounce(func, wait = 15, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
<div class="latest-comments">
<div class="lb-header">Последние комментарии:</div>
<script type="text/javascript" src="https://EXAMPLE.disqus.com/recent_comments_widget.js?num_items=5&amp;hide_avatars=0&amp;avatar_size=26&amp;excerpt_length=150"></script>
</div