Skip to content

Instantly share code, notes, and snippets.

@awerlang
awerlang / Dockerfile
Created December 21, 2017 16:04
Export git repo and build for Docker
FROM rust:1.22.1
WORKDIR /usr/src
RUN git clone --branch 2.9.4 https://github.com/pornel/dssim.git
WORKDIR /usr/src/dssim
RUN cargo build --release
ENTRYPOINT [ "/usr/src/dssim/target/release/dssim" ]
@awerlang
awerlang / no-obj.js
Created December 6, 2017 14:56
memory leaks - #nodejspoa
// não precisa de um objeto ou estado a ser guardado
(function () {
function callMeMaybe() {
setTimeout(() => {
console.log('Node.js POA @ Umbler ' + x);
callMeMaybe();
}, 1000);
}
callMeMaybe();
// from: https://github.com/devongovett/pdfkit/issues/29#issuecomment-103121102
/**
* Parses an input String with the help of the "marked"-package and writes the corresponding elements to the supplied document
* @param doc - the PDFDocument to write to
* @param input - the input String
* @returns {object} - the document for chaining
*/
PDFDocument.parseMarkdown = function (doc, input){
// Array of markdown parts as objects
@awerlang
awerlang / event-emitter.js
Created December 13, 2016 23:43
sample event emitter / observable
require('symbol-observable')
var $$observable = Symbol.observable
var rxjs = require("rxjs")
var Observable = rxjs.Observable
var Subject = rxjs.Subject
var o = new Subject()
var EventEmitter = class {
next(item) {
if (typeof this.observer === 'function') {
/**
Mixes in objects in `properties` into a class.
To be used as a decorator.
@mixin({...})
class MyClass {...}
*/
function mixin(properties: {[key: string]: any}): Function {
if (properties == null) {
throw new Error(`Argument for 'properties' is required.`);
@awerlang
awerlang / CustomError.ts
Created November 16, 2016 15:25
Sample implementation of a custom error
class CustomError extends Error {
get name(): string { return 'CustomError'; };
public stack: any;
constructor(public code: number, public message: string) {
super(message);
if (typeof (<any>Error).captureStackTrace === 'function') {
(<any>Error).captureStackTrace(this, this.constructor);
} else {
@awerlang
awerlang / toJSON.js
Created November 16, 2016 15:21
Convert to JSON, replacing cyclic dependencies
function toJSON(object, fieldsToOmit) {
const map = new Map();
let index = 0;
return JSON.stringify(object, (key, value) => {
if (~fieldsToOmit.indexOf(key)) return undefined;
return value != null && typeof value === 'object'
? map.get(value) || (map.set(value, '$' + ++index), value)
: value;
}, 2);
}
@awerlang
awerlang / webpack.config.js
Created September 5, 2016 14:20
webpack dev config for Angular 2 / Typescript
var webpack = require('webpack');
var path = require('path');
// Webpack Config
var webpackConfig = {
entry: {
'polyfills': './src/polyfills.browser.ts',
'vendor': './src/vendor.browser.ts',
'main': './src/main.browser.ts',
@awerlang
awerlang / ngrxintro.md
Created April 19, 2016 17:50 — forked from btroncone/ngrxintro.md
A Comprehensive Introduction to @ngrx/store - Companion to Egghead.io Series
@awerlang
awerlang / README.md
Last active August 29, 2015 14:27 — forked from hsablonniere/README.md
scrollIntoViewIfNeeded 4 everyone!!!

scrollIntoViewIfNeeded 4 everyone!!!

This gist provides a simple JavaScript implementation of the non-standard WebKit method scrollIntoViewIfNeeded that can be called on DOM elements.

Usage

Just use the code in index.js in your app or website. You can see usage in the test page test.html.

The parent element will only scroll if the element being called is out of the view. The boolean can force the element to be centered in the scrolling area.