Skip to content

Instantly share code, notes, and snippets.

@brunobar79
brunobar79 / getWatcherCounts.js
Last active August 29, 2015 14:11
Find out how many watchers are on the current page (AngularJS)
(function () {
var root = angular.element(document.getElementsByTagName('html'));
var watchers = [];
var f = function (element) {
angular.forEach(['$scope', '$isolateScope'], function (scopeProperty) {
if (element.data() && element.data().hasOwnProperty(scopeProperty)) {
angular.forEach(element.data()[scopeProperty].$$watchers, function (watcher) {
watchers.push(watcher);
@brunobar79
brunobar79 / getGender.py
Created October 18, 2013 20:28
Function to get gender in spanish based on a name
def getGender(name):
name = name.strip()
name_tmp = name.split(" ")
name = name_tmp[0]
name = re.sub(r'[^a-zA-Z0-9]','',name)
#EXCEPTIONAL NAMES GOES HERE
other_female_names = ["clau","pame","flo","stephanie","penelope","pau","liz","solsito","ximme","xime","magali","mabel","maylen","deborah","pame","flo","nicole","jime","pao","mar","angie","karol","janet","pau","fioree","fiore","flor","yante","lau","laau","lau","roo","guadalupe","pilar","valen","ro","caro","caritto","maaite","maite","jazmin","irene","isabel","karen","mercedes","paz","marisol","ayelen","soledad","martu","maru","maruu","elizabeth","jennifer","mily","karem","nicol","sol","rocio","belen","luu","lu","vane","yazmin","carito","lizzette","celeste","vale","miriam","mirian","selene","abril","milagros","belu","nanu","anahi","carmen","giselle","margot","maite","matilde","ines"]
try:
if name.lower()[-1]=="a" or name.lower()[-1].lower()=="i" or name.lower()[-1].lower()=="y" or name.lower() in other_female_names:

How to set up stress-free SSL on an OS X development machine

One of the best ways to reduce complexity (read: stress) in web development is to minimize the differences between your development and production environments. After being frustrated by attempts to unify the approach to SSL on my local machine and in production, I searched for a workflow that would make the protocol invisible to me between all environments.

Most workflows make the following compromises:

  • Use HTTPS in production but HTTP locally. This is annoying because it makes the environments inconsistent, and the protocol choices leak up into the stack. For example, your web application needs to understand the underlying protocol when using the secure flag for cookies. If you don't get this right, your HTTP development server won't be able to read the cookies it writes, or worse, your HTTPS production server could pass sensitive cookies over an insecure connection.

  • Use production SSL certificates locally. This is annoying

@brunobar79
brunobar79 / mobile_redirect.html
Created November 8, 2012 17:59
mobile redirect for dummies
<script>
// <![CDATA[
var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
if(location.href.search("www.")!=-1){
location.href = location.href.replace("www.site.com/", "m.site.com/");
}else{
location.href = location.href.replace("site.com/", "m.site.com/");
}
@brunobar79
brunobar79 / ext.js
Created November 8, 2012 14:10
analytics tracking in chrome extension
var _gaq = _gaq || [];
_gaq['_setAccount'] = 'UA-XXXXX-1';
_gaq['_setDomain'] = 'youdomain.com';
function rand(from,to)
{
return Math.floor(Math.random()*(to-from+1)+from);
}
var i = 1000000000,
@brunobar79
brunobar79 / manifest.json
Created November 8, 2012 13:03
default manifest.json
{
"update_url":"http://clients2.google.com/service/update2/crx",
"name": "Text ext",
"version": "1.0.0",
"description": "Test ext",
"background_page": "html/background.html",
"options_page": "html/options.html",
"permissions": [
"tabs",
"cookies",
@brunobar79
brunobar79 / gist:4038498
Created November 8, 2012 12:21
content_scripts on manifest.json
"content_scripts": [
{
"matches": ["http://*/*", "https://*/*"],
"js": ["script/script_1.js","scripts/script_2.js","script/script_3.js"],
"all_frames": false,
"run_at": "document_end"
}
],
@brunobar79
brunobar79 / background.js
Created March 12, 2012 15:20
background.js extension with browser button
/************************************************************************************
This is your background code.
For more information please visit our wiki site:
http://crossrider.wiki.zoho.com/Background-Code.html
*************************************************************************************/
//Place your code here (ideal for handling toolbar button, global timers, etc.)
/*****************
This background code is showing how to interact with the browser button.