Skip to content

Instantly share code, notes, and snippets.

View asleepwalker's full-sized avatar
🚀
Exploring this planet

Artyom Fedosov asleepwalker

🚀
Exploring this planet
View GitHub Profile
@asleepwalker
asleepwalker / git-remove-credentials.sh
Created January 24, 2017 02:30
Clean your repository if an unwanted file got there
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch database.cfg' --prune-empty --tag-name-filter cat -- --all
var sheet = (function() {
// Create the <style> tag
var style = document.createElement('style');
// Add a media (and/or media query) here if you'd like!
// style.setAttribute('media', 'screen')
// style.setAttribute('media', 'only screen and (max-width : 1024px)')
// WebKit hack :(
style.appendChild(document.createTextNode(''));
var getAbsoluteUrl = (function() {
var a;
return function(url) {
if(!a) a = document.createElement('a');
a.href = url;
return a.href;
};
})();
function once(fn, context) {
var result;
return function() {
if(fn) {
result = fn.apply(context || this, arguments);
fn = null;
}
return result;
function poll(fn, callback, errback, timeout, interval) {
var endTime = Number(new Date()) + (timeout || 2000);
interval = interval || 100;
(function p() {
// If the condition is met, we're done!
if(fn()) {
callback();
}
// If the condition isn't met but the timeout hasn't elapsed, go again
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
@asleepwalker
asleepwalker / array-unique.js
Created April 19, 2016 23:37
Remove duplicates from JavaScript array
var unique = arr.filter(function(item, index) {
return arr.indexOf(item) == index;
});
@asleepwalker
asleepwalker / lowercase.sh
Last active August 12, 2016 10:45
Rename files to lowercase
# Replace '*.JPG' with your name pattern
find . -name '*.JPG' | while read upName; do loName=`echo "${upName}" | tr '[:upper:]' '[:lower:]'`; mv "$upName" "$loName"; done
@asleepwalker
asleepwalker / angular-is-input-filled.js
Created October 13, 2015 13:04
ng-empty | ng-filled
app.config(function($provide) {
$provide.decorator('ngModelDirective', function($delegate) {
var last = $delegate[0].controller.length - 1,
controller = $delegate[0].controller[last],
EMPTY_CLASS = 'ng-empty',
NON_EMPTY_CLASS = 'ng-filled';
$delegate[0].controller[last] = function($scope, $exceptionHandler, $attrs, $element, $parse, $animate) {
controller.apply(this, arguments);
var context = this,
@asleepwalker
asleepwalker / remove-polygon-holes.js
Last active December 4, 2021 05:13
Remove holes from multipolygons in geojson file
// DEPS: npm install jsts@0.17.0
// USAGE: node remove_holes.js holey_coverage.geojson solid_coverage.geojson
var fs = require('fs');
var jsts = require("jsts");
var parser = new jsts.io.GeoJSONParser();
var geojson = JSON.parse(fs.readFileSync(process.argv[2], 'utf8'));
var removedHoles = 0;