Skip to content

Instantly share code, notes, and snippets.

View mahpah's full-sized avatar
🎯
Focusing

mahpah

🎯
Focusing
View GitHub Profile
@mahpah
mahpah / .babelrc
Created October 19, 2016 15:19
Istanbul coverage for babel based nodejs repo
{
"presets": [
"es2015",
"stage-3"
],
"env": {
"test": {
"plugins": [
[
"istanbul",
@mahpah
mahpah / scroll-to-id.js
Created October 31, 2016 10:16
Snippets
/**
* Scroll to id, with defined offset.
* Since we cannot control offset when scroll by anchor
*/
function scrollToId(id, offset = 0) {
let target = document.querySelector(`#${id}`);
if (!target) {
return;
}
@mahpah
mahpah / anti anti copy
Last active February 3, 2017 03:15
all thing public
function removeListener(target) {
for (let key in target) {
if (key.match(/^on/)) {
target[key] = null;
}
}
}
removeListener(document)
removeListener(document.body)
@mahpah
mahpah / find-text-node.js
Created July 7, 2017 02:42
Walk down the element street and find all text nodes
/* @source: https://stackoverflow.com/a/10730777 */
function textNodesUnder(el){
var n, a=[], walk=document.createTreeWalker(el,NodeFilter.SHOW_TEXT,null,false);
while(n=walk.nextNode()) a.push(n);
return a;
}
@mahpah
mahpah / index.html
Last active July 27, 2017 04:56
long polling rxjs
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://unpkg.com/@reactivex/rxjs@5.0.3/dist/global/Rx.js"></script>
@mahpah
mahpah / bson-uuid.ts
Created December 10, 2017 11:23
Convert Bson ObjecId to UUID
/**
* convert bson object id to uuid
* translate from original python version by @enaeseth
* @see https://gist.github.com/enaeseth/5768348
*/
import ObjectId from 'bson-objectid'
const UUID_EPOCH = new Date(1582, 9, 15) // 15 Oct 1582
const UUID_VARIANT_1 = 0b1000000000000000 // wtf?
@mahpah
mahpah / launch.json
Last active March 17, 2018 09:57
VS code launch config for debugging angular app in chrome / chromium and firefox
{
"version": "0.2.0",
"configurations": [{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome with ng serve",
"url": "http://localhost:4200",
"webRoot": "${workspaceRoot}",
"runtimeExecutable": "/usr/bin/chromium-browser",
"skipFiles": [
@mahpah
mahpah / render.js
Created April 24, 2018 07:48
Render pdf with puppeteer
/**
* Usage
* node render.js
*
* curl -O -d '{ "url": "https://google.com" }' http://localhost:9567/any_name.pdf
*
* NOTE: ubuntu 14.04 require some additional package
*
* apt-get install -yq --no-install-recommends \
* libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 \
@mahpah
mahpah / extract-pot.js
Last active July 6, 2018 07:04
Extract template from cs and cshtml file. Please note that injected IStringLocalizer<T> must be named _localizer or _stringLocalizer
#! /usr/bin/node
const fs = require('fs')
const { resolve } = require('path')
const fileHeader = [
'msgid ""',
'msgstr ""',
'"MIME-Version: 1.0\\n"',
'"Content-Type: text/plain; charset=utf-8\\n"',
@mahpah
mahpah / HashSetTest.cs
Last active August 14, 2018 09:02
exclude duplicate elements
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace CsTest.ChangeTracking
{