Skip to content

Instantly share code, notes, and snippets.

function digitNegativeNumbers(): any {
return {
restrict: 'A',
require: 'ngModel',
link(scope: IScope, element: HTMLElement, attrs: any, ngModelCtrl: any) {
function inputValue(val: string) {
if (val) {
const transformedValue = val.replace(/([^-\d.]+)?((-{0,1}\d*\.?\d*)(.*)?$)/, '$3');
if (transformedValue !== val) {
ngModelCtrl.$setViewValue(transformedValue);
var docViewTop = $(window).scrollTop();
var docViewBottom = docViewTop + $(window).height();
var elemTop = $(elem).offset().top;
var elemBottom = elemTop + $(elem).height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
var isYoutube = videoUrl.match(/(?:youtu|youtube)(?:\.com|\.be)\/([\w\W]+)/i);
var isVimeo = videoUrl.match(/^.*(?:vimeo.com)\/(?:channels\/|channels\/\w+\/|groups\/[^\/]*\/videos\/|album‌​\/\d+\/video\/|video\/|)(\d+)(?:$|\/|\?)/);
@natasv
natasv / Prototypes
Last active September 30, 2016 14:18
var Person = function(name) {
this.name = name;
}
Person.prototype.greet = function(){
console.log("Hi, " + this.name);
}
var Developer = function(name, skills) {
Person.apply(this.arguments);
function hiddenClone(element) {
var clone = element.cloneNode(true);
var style = clone.style;
style.position = 'relative';
style.top = window.innerHeight + 'px';
style.left = 0;
document.body.appendChild(clone);
return clone;
}
(function(){
'use strict';
var tau = Math.PI * 2;
var width, height;
var scene, camera, renderer, pointCloud;
function onDocumentReady(){
initialize();
var byteString;
if (dataURI.split(',')[0].indexOf('base64') >= 0)
byteString = atob(dataURI.split(',')[1]);
else
byteString = unescape(dataURI.split(',')[1]);
// separate out the mime component
var mimeString = dataURI.split(',')[0].split(':')[1].split(';')[0];
// write the bytes of the string to a typed array
if (!file) {
return $q.reject(false);
}
return $q(function (resolve, reject) {
var reader = new FileReader();
reader.onloadend = function (response) {
var src = response.target.result;
var imgPromise = srcToDataURI(src);
const stream = {
each: (callback) => {
setTimeout(() => callback(1), 1000);
setTimeout(() => callback(2), 2000);
setTimeout(() => callback(3), 3000);
}
}
createStream.each(console.log)
const dog = () => {
const sound = 'woof'
return {
talk: () => console.log(sound)
}
}
const obj = dog();
obj.talk();