Skip to content

Instantly share code, notes, and snippets.

View pgilad's full-sized avatar
🔭

Gilad Peleg pgilad

🔭
View GitHub Profile
@pgilad
pgilad / gaInit.js
Last active June 22, 2016 22:15
Google Analytics ga.js for chrome extensions - snippit that doesn't report on development enviornment
//replace UA-XXXXXXXX-X *ONLY* with your real UA Account ID.
//DO not replace the UA-99999999-X with anything, as that is the point of this.
var _gaq = _gaq || [];
(function () {
var ga = document.createElement('script');
ga.type = 'text/javascript';
ga.async = true;
ga.src = 'https://ssl.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0];
@pgilad
pgilad / getSubdomain.js
Last active October 10, 2018 11:55
Regex for matching subdomains in document.location.hostname
var getSubdomain = function (baseDomain) {
if (!baseDomain) {
return null;
}
var regSub = new RegExp('^((?!' + baseDomain + '|www)([^.]*))', 'g');
var _subdomain = document.location.hostname.match(regSub);
if (_subdomain && _subdomain[0]) {
return _subdomain[0];
} else {
@pgilad
pgilad / hasEvery.lodash.js
Last active August 29, 2015 14:00
Check if a collection has truthy values for keys
//to validate if a collection has all the desired keys and they are truthy:
var hasEvery = function(desiredKeys, collection) {
return _.all(desiredKeys, _.result.bind(collection, collection));
};
var desiredKeys = ['hello', 'there', 'isIt'];
var collection = { hello: 1, there: 1, isIt: true};
hasEvery(desiredKeys, collection);
//-> true
@pgilad
pgilad / gulpfile.js
Last active November 27, 2017 21:44
gulpfile regular flow
var path = require('path');
var gulp = require('gulp');
var streamqueue = require('streamqueue');
var $gulp = require('gulp-load-plugins')({
lazy: false
});
var prependBowerPath = function (package) {
return path.join('./src/bower_components/', package);
};
@pgilad
pgilad / exposes.md
Created May 25, 2014 10:32
Client exposes API

An API for website's Exposes

Purpose

Imagine you had a Chrome/Firefox/IE? extension that can use the same keys to handle the same basic actions throughout every web page you visit.

Lets assume your are visiting google.com and search for Js Slider. Now you want to move to the next page of results. Currently you have to click Next Page.

But what if Google implements their very own keyboard keys for their search. So they decide that if your press Ctrl+Alt+N you move to the next page. But what if Bing makes it Ctrl+Alt+P? And Yahoo makes it Cmd+Alt+N?

@pgilad
pgilad / Instructions.md
Last active March 31, 2024 22:30
Git commit-msg hook to validate for jira issue or the word merge

Instructions

  • copy the file commit-msg to .git/hooks/commit-msg
  • make sure your delete the sample file .git/hooks/commit-msg.sample
  • Make commit msg executable. chmod +x .git/hooks/commit-msg
  • Edit commit-msg to better fit your development branch, commit regex and error message
  • Profit $$

Shell example

@pgilad
pgilad / res.sh
Created October 27, 2014 13:23
Curl and get only response code
curl -sL -w "%{http_code}" "http://somesite.com" -o /dev/null
@pgilad
pgilad / pre-commit
Created June 30, 2015 06:36
Precommit git hook
#!/bin/sh
JS_FILES=$(git diff --cached --name-only --diff-filter=ACM | grep -E "(.js|.es6)$")
if [ "$JS_FILES" = "" ]; then
exit 0
fi
pass=true
for file in $JS_FILES; do
@pgilad
pgilad / pip-upgrade.py
Created October 25, 2015 09:46
pip upgrade all packages
import pip
import subprocess
for dist in pip.get_installed_distributions():
call_str = "pip install --upgrade {0}".format(dist.project_name)
print
print "Upgrading {}".format(dist.project_name)
subprocess.call(call_str, shell=True)
@pgilad
pgilad / create-temp-dir.yml
Created October 27, 2015 15:08
Create a temp dir cross-platform in ansible
- name: create a local temp directory
local_action:
module: command mktemp -d "{{ lookup('env', 'TMPDIR') | default('/tmp/') }}ansible.XXXX"
register: mktemp_output