Skip to content

Instantly share code, notes, and snippets.

Avatar

Yarin Kessler ykessler

  • appgrinders
  • New York City
View GitHub Profile
@ykessler
ykessler / jquery-shortcuts.js
Created Oct 23, 2022
Two jQuery shortcuts you know you want
View jquery-shortcuts.js
(function($){
$.fn.id = function() {
return $(this).attr('id');
};
$.fn.name = function() {
return $(this).attr('name');
};
})(jQuery);
View BOOKMARKLET: Cached page
javascript: window.location = `http://webcache.googleusercontent.com/search?q=cache:${window.location}`;
@ykessler
ykessler / form-serialize-to-object.js
Created Feb 25, 2021
.serializeToObject() - A jQuery plugin for serializing form data to object
View form-serialize-to-object.js
// TAKEN FROM: https://stackoverflow.com/a/8407771/165673
// IMPORTANT: This does NOT work with nested 'something[other]' type names.
//
// NOTES:
// - To avoid serializing certain input controls, tag them with '.no_serialize' class.
// - Will also ignore any inputs that don't have a name assigned.
// - Handles jQuery UI datepickers well. Doesn't care what format the datepicker uses.
// It will use whatever date format use pass as an option to .serialize_to_object().
//
// REQUIRES:
@ykessler
ykessler / BOOKMARKLET: Markdown snippet
Last active Sep 19, 2020
Generates a markdown link for the page, along with an italicized page description. See also https://gist.github.com/ykessler/9623f5e85258808f24a3e2f03e6f6f0a.
View BOOKMARKLET: Markdown snippet
javascript: var og_site = document.querySelector("meta[property='og:site_name']").getAttribute('content');
var og_title = document.querySelector("meta[property='og:title']").getAttribute('content');
var og_desc = document.querySelector("meta[property='og:description']").getAttribute('content').replace(/\s+/g, " ");
var channel = (og_site == 'YouTube') ? document.querySelector("a.ytp-ce-channel-title").text : null;
var title = og_title ? `${og_title}` : document.title;
if(channel){title = `${title} - ${channel}`};
if(og_site){title = `${title} - ${og_site}`};
if (title) {
var re = /(\\|\/|:|\*|\?|\"|<|>|\|)/gi;
title = title.replace(re, '');
@ykessler
ykessler / BOOKMARKLET: Markdown link
Last active Oct 10, 2020
Generates a markdown link for the page.
View BOOKMARKLET: Markdown link
View BOOKMARKLET: add jquery
// FROM https://stackoverflow.com/a/9624997/165673
javascript:if(!window.jQuery||confirm('Overwrite\x20current\x20version?\x20v'+jQuery.fn.jquery))(function(d,s){s=d.createElement('script');s.src='https://code.jquery.com/jquery.js';(d.head||d.documentElement).appendChild(s)})(document);
View svg_to_png.js
app.post('/svg_to_png', async function (req, res) {
let params = req.body
let image_url = 'https://s3.amazonaws.com/' + params.s3_bucket + '/' + params.s3_key
// STEP 1: Convert SVG to PNG:
var outputBuffer = svg2png.sync(params.svg_data, {});
// STEP 2: Upload to S3:
let s3_params = {
@ykessler
ykessler / postgres_arrays.sql
Created Sep 25, 2018
Examples of two types of syntax for postres arrays.
View postgres_arrays.sql
-- Examples of two types of syntax for postres arrays.
-- EXAMPLE 1 AND 2 ARE THE SAME:
-- EXAMPLE 1 - ARRAY SYNTAX:
INSERT INTO sample_table
VALUES (
ARRAY[10000, 20000, 30000, 40000],
ARRAY['red', 'blue', 'green'],
ARRAY[['meeting', 'lunch'], ['training', 'presentation']]
View BOOKMARKLET: Copy page title
javascript:var title=document.title;if(title){var re=/(\\|\/|:|\*|\?|\"|<|>|\|)/gi;title=title.replace(re,'');void(prompt('Page Title', title));}