Skip to content

Instantly share code, notes, and snippets.

type description release type
@micmro
micmro / .zshrc
Last active January 12, 2017 22:50
Automatically add ssh key to ssh-agent in shell if it had not been added yet
# add ssh key to ssh-agent if it had not been added yet
ssh-add -l | grep -q "$HOME/.ssh/id_rsa" || ssh-add $HOME/.ssh/id_rsa
@micmro
micmro / manual-typing-of-npm-module.d.ts
Last active November 22, 2021 09:15
Add a custom type definition file for an existing (non-typed) npm module, while automatically pick up the typing (for both Typescript or Javascript in case of VS Code). Typings are contained in the `typings/` directory
//real file is in: `typings/swagger-express-mw/index.d.ts` (relative to tsconfig.json)
import {Config, ConnectMiddleware} from "../swagger-node-runner"
/**
* Create a new instance of Connect specific SwaggerNodeRunner
*/
export function create(config: Config, cb: {(err: Error | undefined, runner: ConnectMiddleware): void}): void
@micmro
micmro / Dockerfile
Last active February 12, 2016 07:24
WSO2 Identity Server 5.1 Dockerfile
FROM clifton/oracle-java8
COPY /wso2is-5.1.0 /opt/wso2is
EXPOSE 9443
CMD ["/opt/wso2is/bin/wso2server.sh"]
@micmro
micmro / fix-flex-svg-panels.html
Last active December 28, 2017 10:35
SVG with both fixed width (pixel) and flexible with (percentage) panels combined - https://jsfiddle.net/4xuLyvj9/ - does not work in IE/Edge due to lack of support for SVG in `foreignObject`
<html>
<body>
<svg width="100%" height="250" xmlns="http://www.w3.org/2000/svg">
<foreignObject id="fixed-panel" width="100" height="100%">
<svg width="100" xmlns="http://www.w3.org/2000/svg">
<rect x="0" y="0" width="100" height="100%" fill="#fcc" rx="5" ry="5"/>
<text x="5%" y ="25" width="100" fill="#333">fixed width</text>
</svg>
</foreignObject>
<foreignObject id="flex-panel" width="100%" height="100%" style="padding-left:100px;">
@micmro
micmro / jquery.asyncOn
Last active August 29, 2015 14:16
Non blocking event listener for jQuery
/*
* usage: exactly like like jQuery's `on`
* $("#xyz").on("click", function(){ ... }); => $("#xyz").asyncOn("click", function(){ ... });
* $("#xyz").one("click", function(){ ... }); => $("#xyz").asyncOne("click", function(){ ... });
*/
$.fn.extend({
asyncOn : function(types, selector, data, fn, one){
/*based on https://github.com/jquery/jquery/blob/361a0d5150a1c57b1857611cde1b05bd0ef21a50/src/event.js*/
var type, origFn;
@micmro
micmro / cssToJSVariable.js
Created November 20, 2014 04:14
Grunt-task for a quick and dirty conversion from a CSS file to a JS file containing the CSS as a variable
//transform CSS file to JS variable
grunt.registerTask("inlineCssToJs", function() {
var cssFile = "src/style.css";
var cssFileDestination = "dist/style.js";
var varName = "cssFileText";
var cssContent = grunt.file.read(cssFile);
//clean CSS content
cssContent = cssContent.replace( /\/\*(?:(?!\*\/)[\s\S])*\*\//g, "").replace(/[\r\n\t]+/g, " ").replace(/[ ]{2,}/g, " ").replace(/\"/g,"\\\"");
@micmro
micmro / ResourceDuration
Created November 19, 2014 04:49
Page Resources ordered by duration
window.performance.getEntriesByType("resource").sort(function(a, b) {
return b.duration - a.duration;
}).forEach(function(a){
console.log(Math.floor(a.duration), a.name);
});
@micmro
micmro / third-party-calls.sql
Last active August 29, 2015 14:07
bigQuery HTTP Archive - requests
/* WIP - not working yet */
SELECT
NTH(10, num_requests) thenth,
NTH(25, num_requests) twenty_fifth,
NTH(50, num_requests) median,
NTH(75, num_requests) seventy_fifth,
NTH(90, num_requests) ninetieth
FROM(
SELECT COUNT(*) num_requests
@micmro
micmro / mean.sublime-project
Created June 30, 2014 14:16
MEAN.ie Sublime project file
{
"folders":
[
{
"path": ".",
//"name" : "Mean Project Name",
"file_exclude_patterns": [
"mean-dev.*"
,"local.*"
,"LICENSE"