Skip to content

Instantly share code, notes, and snippets.

View styfle's full-sized avatar

Steven styfle

View GitHub Profile
@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();
@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;
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 / 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*
@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 / 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 / after-promisify.js
Created May 10, 2017 01:37
Promises in Node.js 8.x Core
const promisify = require('util').promisify;
const fs = require('fs');
const stat = promisify(fs.stat);
const writeFile = promisify(fs.writeFile);
const appendFile = promisify(fs.appendFile);
async function exists(f) {
try {
const stats = await stat(f);
return true;
@styfle
styfle / requirePromise.js
Created May 10, 2017 01:40
Promises in Node.js 8.x Core
function requirePromise(modName, fnName) {
return require('util').promisify(require(modName)[fnName]);
}
const stat = requirePromise('fs', 'stat');
const writeFile = requirePromise('fs', 'writeFile');
const appendFile = requirePromise('fs', 'appendFile');
@styfle
styfle / .htaccess
Last active November 12, 2018 17:04
Apache config for a https enabled, secure headers, cache headers, etc
## Set security headers per https://observatory.mozilla.org
Header set Strict-Transport-Security "max-age=15768000" env=HTTPS
Header set Content-Security-Policy "frame-ancestors 'self'"
Header set X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options "nosniff"
## Add some rewrite rules per https://stackoverflow.com/a/13997498/266535
RewriteEngine On
@styfle
styfle / web.config.xml
Created July 13, 2017 15:14
Security and Caching settings for web.config in ASP.NET
<system.web>
<httpCookies requireSSL="true" />
</system.web>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Strict-Transport-Security" value="max-age=31536000"/>
<add name="X-XSS-Protection" value="1; mode=block"/>
<add name="X-Content-Type-Options" value="nosniff"/>