Skip to content

Instantly share code, notes, and snippets.

View raam86's full-sized avatar

Raam Rosh-Hai raam86

  • Amsterdam, Netherlands
View GitHub Profile
@raam86
raam86 / gist:6646078
Last active December 23, 2015 13:59
Think Bayes cookie problem
class Jar:
def __init__(self,mix):
self.mix = mix
#Yey map reduce!
self.q = reduce(lambda x, y:x+y,map(lambda key:mix[key], mix))
def Likelyhood(self,data):
bag, color = data
mix = self.hypotheses[hypo][bag]
like = mix[color]
self.q = self.q -1
@raam86
raam86 / gist:6569089
Created September 15, 2013 09:12
track adwords conversions
function trackConv(google_conversion_id,google_conversion_label){var image=new Image(1,1);image.src="http://www.googleadservices.com/pagead/conversion/"+google_conversion_id+"/?label="+google_conversion_label+"&script=0";console.log(image);}
@raam86
raam86 / og:tag bookmarklet
Last active December 22, 2015 02:28
og:tag generator in a bookmarkelt!
function makeTag(type,content){
return $("<meta property='og:"+type+ "'" +" content='" +content + "'/>");
}
jQuery('body').prepend('<div id="ogf"><small>Press enter key to get your meta</small>'+
'<input id="fbtitle" value="Your Title" />'+
'<input id="fbimage" value="Your image url" />'+
'<input id="fburl" value="Your url" />'+
'<input id="fbsite_name" value="Your sitename" />'+
'<input id="fbtype" value="Your type" />'+
'</div>').hide().slideDown();
@raam86
raam86 / Factorial C
Created August 27, 2013 10:04
First C programme
#include <stdio.h>
// To execute C, please define "int main()"
double fac(double n){
if(n == 0){
return 1.0;
}
return n * fac(n-1);
@raam86
raam86 / gist:5865228
Created June 26, 2013 06:35
Bookmarklet to discover google analytics UA on sites
javascript:(function(){var a=document.head.innerHTML.match(/UA-\d+-\d/);
if (a){
b=document.createElement("a");
b.appendChild(document.createTextNode(a));
b.setAttribute("style","background:#000;color:#fff;position:fixed;top:0;font-size:39px");
}
else{
b=document.createElement("span");
b.setAttribute("style","color:red;height:50px;display:block;position:fixed;top:0");
b.appendChild(document.createTextNode("no analytics found"));
@raam86
raam86 / gist:5865091
Created June 26, 2013 06:08
Access same domain iFrame and change attributes
window.onload = function () {
var iframe = document.getElementById('IFwinEdit_Form_303282');
var innerDoc = (iframe.contentDocument) ? iframe.contentDocument : iframe.contentWindow.document;
var submit = innerDoc.getElementById('submit');
submit.setAttribute('class', 'subButton');
};
@raam86
raam86 / CheckALT
Last active September 10, 2021 00:30
Check image alt tags existance with a bookmarklet. Great for SEO people.
javascript: (function (e, a, g, h, f, c, b, d) {
if (!(f = e.jQuery) || g > f.fn.jquery || h(f)) {
c = a.createElement("script");
c.type = "text/javascript";
c.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + g + "/jquery.min.js";
c.onload = c.onreadystatechange = function () {
if (!b && (!(d = this.readyState) || d == "loaded" || d == "complete")) {
h((f = e.jQuery).noConflict(1), b = 1);
f(c).remove()
}
@raam86
raam86 / change attribute on scroll
Created June 25, 2013 08:56
Change any css attribute on scroll event. Removed when scrollHeight is less then specified. Supports modern browsers and IE9+
function scrolled(elementId, scrollHeight, cssAttribute, value) {
var el = document.getElementById(elementId);
if (window.pageYOffset >= scrollHeight) {
el.setAttribute('style', cssAttribute + ':' + value + ';');
} else {
el.removeAttribute('style');
}
}