Skip to content

Instantly share code, notes, and snippets.

View stevedya's full-sized avatar
🤠

Steve Stein stevedya

🤠
View GitHub Profile
@stevedya
stevedya / CountWithCommas.js
Last active June 11, 2018 19:56
jQuery - Number Counter with Commas
//Call the function on scroll
$(window).scroll(numberCounter);
//Check if in viewport function
function inViewport(el, val) {
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elTop = $(el).offset().top;
var elBottom = elTop + $(el).height();
@stevedya
stevedya / video-embed.js
Created February 22, 2019 21:32
Vue filter for youtube and vimeo embeds
Vue.filter('videoUrl', function (url) {
//youtube
if (url.includes('youtube') || url.includes('youtu.be')) {
//Get id
url = url.split(/(vi\/|v=|\/v\/|youtu\.be\/|\/embed\/)/);
let id = (url[2] !== undefined) ? url[2].split(/[^0-9a-z_\-]/i)[0] : url[0];
return 'https://www.youtube.com/embed/' + id
} else if (url.includes('vimeo')) {
var url = url.match(/(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/(?:[^\/]*)\/videos\/|album\/(?:\d+)\/video\/|video\/|)(\d+)(?:[a-zA-Z0-9_\-]+)?/i);
return 'https://player.vimeo.com/video/' + url[1]
@stevedya
stevedya / youtube-vimeo-video-id-regex.py
Created March 15, 2019 15:45
Using regex this gist will return video ID's from strings
import re
# Vimeo
vimeo_url = 'https://vimeo.com/56282283'
# Regex to strip id from video string
match_pattern = r'^(?:https?:)?(?:\/\/)?(?:www\.|player\.)?vimeo.com\/(?:channels\/(?:\w+\/)?|groups\/([^\/]*)\/videos\/|album\/(\d+)\/video\/|video\/|)(\d+)(?:$|\/|\?)'
response = re.search(match_pattern, url).group(3)
if response:
print (response)
$(document).ready(function () {
var creditCardField = $('#card-element');
creditCardField.on('keyup', function () {
//Turn card number into string for substring method
var creditCardString = creditCardField.val().toString();
if (creditCardString.length < 2) {
//Hide all cards
@stevedya
stevedya / bubble-sort.py
Created July 12, 2019 17:49
bubble sort example
def sort(nums):
for i in range(len(nums) - 1, 0, -1):
for j in range(i):
if nums[j] > nums[j + 1]:
temp = nums[j]
nums[j] = nums[j + 1]
nums[j + 1] = temp
nums = [5, 3, 8, 6, 7, 2]
@stevedya
stevedya / select-sort.py
Created July 12, 2019 17:50
select sort example
def selectSort(nums):
for i in range(5):
minpos = i
for j in range(i, 6):
if nums[j] < nums[minpos]:
minpos = j
temp = nums[i] #hold old value
nums[i] = nums[minpos] #put new min value where old one was
nums[minpos] = temp #put old value where min used to be
@stevedya
stevedya / smoothscroll.js
Created December 30, 2019 20:52
Smooth Scroll to ID with pure javascript
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
function isVisible (ele) {
const { top, bottom } = ele.getBoundingClientRect();
const vHeight = (window.innerHeight || document.documentElement.clientHeight);
return (
(top > 0 || bottom > 0) &&
top < vHeight
);
}
@stevedya
stevedya / tidytext.R
Last active May 5, 2020 23:40
Tidy Text Example in R Stripping out numeric, punc, and replace words
library(dplyr)
library(tidytext)
library(ggplot2)
data <- read.csv('/Users/steven/Desktop/JEOPARDY_CSV.csv')
text_set <- iconv(data$Question, to = "utf-8-mac")
clean_text <- text_set %>%
as_tibble() %>%
unnest_tokens(word, value, to_lower = TRUE, strip_punct = TRUE, strip_numeric = TRUE) %>%
@stevedya
stevedya / inset-mixin.scss
Created September 23, 2020 17:55
Inset Sass Mixin
/* ============================================
Inset helper for quick top, right, bottom, left properties.
Use until the inset: css property has better browser support
https://caniuse.com/mdn-css_properties_inset
*/
@mixin inset($top: 0, $right: 0, $bottom: 0, $left: 0) {
top: $top;
right: $right;
bottom: $bottom;