Skip to content

Instantly share code, notes, and snippets.

@micmro
micmro / .zshrc
Last active Jan 12, 2017
Automatically add ssh key to ssh-agent in shell if it had not been added yet
View .zshrc
# 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 Nov 22, 2021
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
View manual-typing-of-npm-module.d.ts
//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 Feb 12, 2016
WSO2 Identity Server 5.1 Dockerfile
View 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 Dec 28, 2017
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`
View fix-flex-svg-panels.html
<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 Aug 29, 2015
Non blocking event listener for jQuery
View jquery.asyncOn
/*
* 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 Nov 20, 2014
Grunt-task for a quick and dirty conversion from a CSS file to a JS file containing the CSS as a variable
View cssToJSVariable.js
//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 Nov 19, 2014
Page Resources ordered by duration
View ResourceDuration
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 Aug 29, 2015
bigQuery HTTP Archive - requests
View third-party-calls.sql
/* 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 Jun 30, 2014
MEAN.ie Sublime project file
View mean.sublime-project
{
"folders":
[
{
"path": ".",
//"name" : "Mean Project Name",
"file_exclude_patterns": [
"mean-dev.*"
,"local.*"
,"LICENSE"