Skip to content

Instantly share code, notes, and snippets.

View swape's full-sized avatar
😎

Alireza Balouch swape

😎
  • Mjolnir Media AS
  • Kongsberg, Norway
  • 01:28 (UTC +02:00)
View GitHub Profile
@swape
swape / cloudSettings
Last active August 24, 2020 13:10
vscode settings
{"lastUpload":"2020-08-24T13:10:51.256Z","extensionVersion":"v3.4.3"}
@swape
swape / pre-commit
Created April 11, 2017 21:00
pre-commit script to prevent merge markers from being committed
#!/bin/sh
## pre-commit script to prevent merge markers from being committed.
## filename: .git/hooks/pre-commit
changed=$(git diff --cached --name-only)
if [[ -z "$changed" ]]
then
exit 0
@swape
swape / ondomchange.js
Created October 21, 2015 16:46
detecting DOM changes
var observeDOM = (function(){
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
eventListenerSupported = window.addEventListener;
return function(obj, callback){
if( MutationObserver ){
var obs = new MutationObserver(function(mutations, observer){
if( mutations[0].addedNodes.length || mutations[0].removedNodes.length )
callback();
});
obs.observe( obj, { childList:true, subtree:true });
@swape
swape / b.js
Last active August 29, 2015 14:27
Require js files from a directory with glob based on a file name.
// ./controllers/b.js
module.exports = {
index: function(){
console.log('b is here');
}
};
@swape
swape / moveFiles.rb
Last active August 29, 2015 14:26
ruby script for moving files to directories based on [filetype]/[year]/[month]/[filename] from recovered files on mac using PhotoRec.
puts '----Starting the move'
dir_target = '/Volumes/backup/recfiles'
#moving the files
def moveFiles (myfile)
fileType = File.extname(myfile)[1..-1]
targetPath = "/Volumes/backup/recovered/#{fileType}/";
fileTime = File.mtime(myfile)
fileYear = Time.at(fileTime).year
@swape
swape / post-receive
Created May 6, 2015 08:31
This git hook is copying the prod branch to prod dir and dev branch to dev dir. Makes it easy to deploy.
#!/bin/bash
echo "-- running post receive --";
while read oldrev newrev ref
do
if [[ $ref =~ .*/dev$ ]];
then
git --work-tree=/var/www/html/dev --git-dir=/home/git/ checkout dev -f
fi
@swape
swape / 0_reuse_code.js
Last active August 29, 2015 14:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@swape
swape / email-pattern.js
Created October 21, 2014 07:16
Validating email pattern
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
@swape
swape / designer.html
Created June 26, 2014 11:15
designer
<link rel="import" href="../core-icon-button/core-icon-button.html">
<link rel="import" href="../core-toolbar/core-toolbar.html">
<link rel="import" href="../core-scroll-header-panel/core-scroll-header-panel.html">
<polymer-element name="swape-test">
<template>
<style>
:host {
position: absolute;
@swape
swape / ie-console-mute
Created May 14, 2014 13:19
Make IE not complain about console.log
<!--[if IE]>
<script type="text/javascript">
var console = { log: function() {} };
</script>
<![endif]-->