Skip to content

Instantly share code, notes, and snippets.

Thodoris Greasidis thgreasi

Block or report user

Report or block thgreasi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View $any.sublime-snippet
<!-- place at ~/.config/sublime-text-3/Packages/User/$any.sublime-snippet -->
<snippet>
<content><![CDATA[
{
\$any: {
\$alias: '${1:this}',
\$expr: {
${1:this}: {
},
},
@thgreasi
thgreasi / debouceWithResult.js
Last active Aug 19, 2018
[Moved to https://github.com/thgreasi/debounce-with-result.js] An improved version of debounce that returns a Promise and can handle return values. Returns a single Promise for each separate group of debounced invocations.
View debouceWithResult.js
function debounceWithResult (func, wait, immediate) {
function newDeferred () {
var deferred = {};
deferred.promise = new Promise(function (resolve, reject) {
deferred.resolve = resolve;
deferred.reject = reject;
});
return deferred;
}
@thgreasi
thgreasi / appNamespace.appManager.js
Last active Apr 25, 2016
AngularJS lifecycle app manager
View appNamespace.appManager.js
(function () {
"use strict";
window.appNamespace = window.appNamespace || {};
appNamespace.appManager = appNamespace.appManager || new AppManager();
function AppManager() {
this.currentAppName = '';
this.currentApp = null;
@thgreasi
thgreasi / firebaseCheckpointArray.js
Last active Sep 20, 2017
firebase.checkpointArray
View firebaseCheckpointArray.js
/*
Implemented by katowulf at:
https://jsfiddle.net/katowulf/1dfyz2rq/
Discussed in:
https://github.com/firebase/angularfire/issues/687
https://github.com/angular-ui/ui-sortable/issues/421
*/
angular.module('firebase.checkpointArray', ['firebase'])
.factory('firebaseCheckpointArray', function($firebaseArray) {
View PromiseGeneratorConsumers.js
// iterate till first success
new Promise((resolve) => {
runGeneratorOnce(myPromiseGenerator, initialValue);
function runGeneratorOnce(pg, result) { var status = pg.next(result);
if (status.done) { reject(); return; }
status.value.then(resolve).catch(value => {
return runGeneratorOnce(pg, value);
@thgreasi
thgreasi / es7
Last active Aug 29, 2015
LocalForage setDriver Looper
View es7
async function setDriver(driverNames) {
for (var driverName of driverNames) {
if (this.supports(driverName) {
try {
let driver = await this.getDriver(driverName).then(driver => driver._initDriver());
if (driver) {
return Promise.resolve(driver);
}
} catch (e) { }
}
@thgreasi
thgreasi / syncVSasyncLoopOver.js
Last active Aug 29, 2015
sync vs async loop over
View syncVSasyncLoopOver.js
function getParam(x) { }
function myFunc(argument) { }
function myAsyncFunc(argument) { return new Promise(function(resolve, reject) { /* ... */ }); }
//========== sync loop over
for (var i = 0; i < l; i++) {
try {
var result = myFunc(getParam(i));
@thgreasi
thgreasi / crossGet.js
Created Sep 27, 2014
crossGetProviders
View crossGet.js
var crossGetProviders = {
whateverorigin: function crossGet(url) {
var promise = $.getJSON('http://whateverorigin.org/get?url=' + encodeURIComponent(url) +
'&callback=?');
var piped = promise.then(function (response) {
return response.contents;
});
return piped;
},
corsproxy: function corsproxy(url) {
View jquery.simulate.dragpath.js
;(function($, undefined) {
function findCenter(elem) {
var offset,
document = $(elem.ownerDocument);
elem = $(elem);
offset = elem.offset();
return {
x: offset.left + elem.outerWidth() / 2 - document.scrollLeft(),
y: offset.top + elem.outerHeight() / 2 - document.scrollTop()
@thgreasi
thgreasi / gen.genericDirectives.js
Last active Aug 29, 2015
A simple directive to dynamically load proper directive based on the type of the provided model
View gen.genericDirectives.js
(function() {
"use strict";
angular.module('gen.genericDirectives', [])
.directive('genDynamicDirective', ['$compile',
function($compile) {
return {
restrict: "E",
require: '^ngModel',
scope: true,
You can’t perform that action at this time.