Skip to content

Instantly share code, notes, and snippets.

View styfle's full-sized avatar

Steven styfle

View GitHub Profile
@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 / 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;
@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 / 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"/>
@styfle
styfle / 41705559.ts
Created November 17, 2017 15:04
TypeScript SO question 41705559
type Opt = { id: string, name: string }
interface MultiProps {
isMultiple: true;
options: Opt[];
id: string[];
onChange: (id: string[]) => void;
}
interface SingleProps {
@styfle
styfle / 49156502.ts
Created March 7, 2018 17:55
Answer to stackoverflow question 49156502
function isDate(obj: any): obj is Date {
return typeof obj === 'object' && 'toISOString' in obj;
}
function isString(obj: any): obj is string {
return typeof obj === 'string';
}
interface JWT {
id: string;