Skip to content

Instantly share code, notes, and snippets.

@nadav-dav
nadav-dav / download intercom invoices.js
Last active February 20, 2018 09:54
download intercom invoices (print to pdf)
// works on Chrome (need async-await support)
// go to https://app.intercom.io/a/apps/<APP ID>/billing/invoices
// and run this:
(async function(){
const printPdf = function (url, title) {
let iframe;
return new Promise((resolve, reject)=> {
console.log(url, title)
iframe = document.createElement('iframe');
@nadav-dav
nadav-dav / __usage example
Last active August 3, 2017 12:02
creating custom react-scripts (without ejecting) - it is ugly but it works
usage:
node ./custom-react-scripts start
@nadav-dav
nadav-dav / ServerSideRenderer.js
Created July 24, 2016 11:26
Server side render with React and Express
var React = require('react');
var ReactDom = require('react-dom/server');
import {match, RouterContext} from "react-router";
import Main from "../../app/Main";
import routes from "../../app/routes";
export default class ServerSideRenderer {
static render(req) {
return new Promise((resolve, reject)=> {
@nadav-dav
nadav-dav / dom2comp.js
Created March 15, 2016 10:37
React: Getting a component from a DOM element
let searchRoot = ReactDom.render(React.createElement(Main), document.getElementById('main'));
try {
var getComponent = (comp) => comp._renderedComponent ? getComponent(comp._renderedComponent) : comp;
var getComponentById = (id)=> {
var comp = searchRoot._reactInternalInstance;
var path = id.substr(1).split('.').map(a=> '.' + a);
if (comp._rootNodeID !== path.shift()) throw 'Unknown root';
while (path.length > 0) {
comp = getComponent(comp)._renderedChildren[path.shift()];
@nadav-dav
nadav-dav / gist:8002502
Created December 17, 2013 09:49
example: how to user swfobject
<head>
<!--
first, download "swfobject.js" from the site i sent you and place it in your folder
-->
<script type="application/javascript" src="swfobject.js"></script> <!-- this make sure the swfobject.js is loaded -->
<script type="application/javascript">
document.onreadystatechange = function () {
if(document.readyState === "complete"){
// insert here the container id you wish to embed the swf in it
var el = document.getElementById("my-target-element");
@nadav-dav
nadav-dav / gist:7855155
Last active December 30, 2015 16:29
Osx ding tip!

Here is a tip! add this function to your .bashrc / .profile file:

function ding(){
  if [[ $? != 0 ]] ; then
    afplay /System/Library/Sounds/Basso.aiff
  else
    afplay /System/Library/Sounds/Glass.aiff
  fi
}