Skip to content

Instantly share code, notes, and snippets.

@vctrfrnndz
vctrfrnndz / letteravatar.js
Created May 18, 2015 17:06
Generate SVG letter avatar
function drawCircle(text, size, color) {
var textSize = Math.ceil(size / 2.5);
var font = 'Proxima Nova, proxima-nova, HelveticaNeue-Light, Helvetica Neue Light, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif';
var colors = ["#1abc9c", "#16a085", "#f1c40f", "#f39c12", "#2ecc71", "#27ae60", "#e67e22", "#d35400", "#3498db", "#2980b9", "#e74c3c", "#c0392b", "#9b59b6", "#8e44ad", "#bdc3c7", "#34495e", "#2c3e50", "#95a5a6", "#7f8c8d", "#ec87bf", "#d870ad", "#f69785", "#9ba37e", "#b49255", "#b49255", "#a94136"];
var colorIndex = Math.floor((text.charCodeAt(0) - 65) % colors.length);
var finalColor = color || colors[colorIndex];
var template = [
'<svg height="' + size + '" width="' + size + '" style="background: ' + finalColor + '">',
'<text text-anchor="middle" x="50%" y="50%" dy="0.35em" fill="white" font-size="' + textSize + '" font-family="' + font + '">' + text.toUpperCase() + '</text>',
function scrollAnimated(to, duration) {
var start = $(window).scrollTop(),
change = to - start,
currentTime = 0,
increment = 20;
function easeInOut(currentTime, startValue, change, duration) {
currentTime /= duration / 2;
if (currentTime < 1) {
@vctrfrnndz
vctrfrnndz / debounce.js
Last active November 8, 2019 04:23
Debounce
function debounce(func, wait, 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;
Avatar Generator from Name
--------------------------
A name (first name and surname) is input and output using the initials from the name and a background colour (based on the first name first letter). The background colors are from from http://flatuicolors.com/
@vctrfrnndz
vctrfrnndz / gist:6526989.less
Last active December 22, 2015 20:29
Ultimate grid mixin
// Group class for clearing floats
.group {
&:before,
&:after {
content: " ";
display: table;
}
&:after {
@vctrfrnndz
vctrfrnndz / gist:5105351.php
Last active December 14, 2015 15:08
Youtube id regular expression (getting url from Wordpress meta tag)
$video_url = get_post_meta( get_the_ID(), 'mb_youtube_url', true );
// Parse video ID from given url
if (preg_match('%(?:youtube(?:-nocookie)?\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})%i', $video_url, $match)) {
$video_id = $match[1]; // Return video ID
}
@vctrfrnndz
vctrfrnndz / gist:4642918.php
Last active December 11, 2015 18:38
Obtain a list of videos from a Vimeo account using PHP
<?php
// Account to get the videos from
$username = 'user6002596';
// Do request to Vimeo API
$request = 'http://vimeo.com/api/v2/'. $username .'/videos.xml';
// Parse into SimpleXML object
$vimeo = simplexml_load_file($request);
@vctrfrnndz
vctrfrnndz / equalizer.js
Created October 29, 2015 19:50
Calculate equal height based on content
function heightEqualizer($row) {
var $columns = $row.find('> *');
function calculateHeight($el) {
var height = 0;
$el.each(function() {
var heightVal = $(this).css('height');
$(this).css('height', '');
@vctrfrnndz
vctrfrnndz / sticky.js
Last active August 29, 2015 14:28
Sticky
$(window)
.on('scroll', onScroll);
function onScroll() {
var sticky = $('.js-sticky-nav').filter(':visible');
if (sticky.length) {
toggleSticky(sticky);
}
}
@vctrfrnndz
vctrfrnndz / val.js
Created July 8, 2015 17:03
input validations
function inputValidations() {
function isAlphaNumeric(val) {
var letter = /[a-zA-Z]/,
number = /[0-9]/;
var valid = number.test(val) && letter.test(val);
return valid;
}