Skip to content

Instantly share code, notes, and snippets.

View styfle's full-sized avatar

Steven styfle

View GitHub Profile
@styfle
styfle / before-promisify.js
Created May 10, 2017 01:34
Promises in Node.js 8.x Core
const fs = require('fs');
function exists(f, callback) {
fs.stat(f, (err) => {
callback(err ? false : true);
});
}
function main() {
const filename = './example.txt';
@styfle
styfle / html-table-to-markdown-table.js
Created September 19, 2016 20:44
Convert an HTML Table in the DOM to a Markdown Table as a string
function toMarkdown(doc) {
let s = '| ';
let thead = doc.querySelector('thead');
let headcells = thead.querySelectorAll('td');
for (let i = 0; i < headcells.length; i++) {
let cell = headcells[i];
s += cell.textContent.trim() + ' | ';
}
@styfle
styfle / jquery.atwho.d.ts
Created August 27, 2015 23:16
First attempt at type definitions for atwho
interface JQueryAtWhoOptions<T> {
// key char for observing such as `@`
at?: string;
/*
alias name of `at`
it would be an id attribute of the popup view.
*/
alias?: string;
/*
should be a plain object *Array* or a *URL*
var promiseArray = [];
function foo(i) {
var def = $.Deferred();
// This line represents some async code: ajax, setTimeout, etc
setTimeout(function() {def.resolve(i); }, i);
// Return the promise which may not be resolved yet
return def.promise();
}
@styfle
styfle / Search Current Site
Created February 4, 2012 18:42 — forked from anonymous/Search Current Site
A Bookmarklet that searches the current site using Google.
javascript:var%20u%20=%20document.URL;%20%20var%20a%20=%20u.split("://");%20var%20protocol%20=%20a[0];%20var%20temp%20=%20a[1];%20%20a%20=%20temp.split("/");%20var%20fullDomain%20=%20a[0];%20var%20theRest%20=%20a[1];%20%20var%20q%20=%20window.prompt("Search%20"+fullDomain+"%20for:%20","");%20q%20=%20q.replace("%20",%20"+");%20document.location%20=%20"http://www.google.com/search?btnG=1&pws=0&q=site%3A"+fullDomain+"+"+q;
@styfle
styfle / gist:1102255
Created July 24, 2011 04:41
Facebook chat fixer. Paste in your URL to hide inactive users.
javascript:var friends = document.getElementsByClassName('fbChatOrderedList')[1].getElementsByClassName('item'); for (var i=0;i<friends.length; i++) { if (friends[i].className != "item active") friends[i].style.display = "none"; } ChatSidebar.toggle(); ChatSidebar.toggle();