Skip to content

Instantly share code, notes, and snippets.

View heldrida's full-sized avatar
🇲🇿
Peace for Mozambique!

Helder Oliveira heldrida

🇲🇿
Peace for Mozambique!
View GitHub Profile
import React, { PropTypes } from 'react'
export const insertScriptHelper = (projectId) => {
const el = document.querySelector('[data-optimizely-snippet]')
if (!isReadyHelper() && !el) {
const protocol = `${document.location.protocol}//`
const scriptTag = document.createElement('script')
scriptTag.type = 'text/javascript'
scriptTag.async = true
scriptTag.src = `${protocol}cdn.optimizely.com/js/${projectId}.js`
@heldrida
heldrida / timed-recursive-calls-with-timer.babel.js
Last active February 28, 2017 11:12
A helper function that make's timed recursive calls, if a given condition does not pass, after a given amount of time in milliseconds. When the condition test pass, a callback function is called. For each recursive step call, there is a stepCallback if required.
let global = {
stop: false
}
const timedCaller = (params) => {
params.debug && console.log('[DEBUG ' + params.name + '] fn call')
// Test condition, if true run the callback
if (params.condition.test()) {
params.debug && console.log('[DEBUG ' + params.name + '] condition test passed!')
if (typeof params.condition.callback === 'function') {
params.debug && console.log('[DEBUG ' + params.name + '] callback is fn, should call!')
@heldrida
heldrida / famousjs-lesson101(starterKit-picasa-album)
Created September 16, 2014 22:06
Famo.us lesson 101 (Starter kit), picasa album link is invalid! Here's a solution
define(function(require, exports, module) {
var SlideData = {
picasaUrl: 'https://picasaweb.google.com/data/feed/api/all',
queryParams: '?kind=photo&q=puppy&max-results=5&imgmax=720&alt=json',
defaultImage: 'https://lh4.googleusercontent.com/-HbYp2q1BZfQ/U3LXxmWoy7I/AAAAAAAAAJk/VqI5bGooDaA/s1178-no/1.jpg'
};
SlideData.getUrl = function() {
return SlideData.picasaUrl + SlideData.queryParams;
};
@heldrida
heldrida / Gruntfile.js
Created August 21, 2014 09:04
Gruntfile.js: Basic watch configuration, observing html, sass and javascript files
/*globals module, grunt*/
'use strict';
module.exports = function (grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
@heldrida
heldrida / javascript
Last active March 11, 2024 17:00
Facebook Javascript SDK: Basic Login and Logout example
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: 'xxxxxxxxxxxxx',
status: true,
cookie: true,
xfbml: true
});
@heldrida
heldrida / gist:6232505
Created August 14, 2013 16:03
Facebook: Post on behalf
<?php
$facebook = new Facebook(array(
'appId' => 'xxxxx',
'secret' => 'xxxxx'
)
);
$facebook->setExtendedAccessToken();
$access_token = $facebook->getAccessToken();
@heldrida
heldrida / gist:5188729
Created March 18, 2013 16:52
videojs, with fallback firefox safari
var link = document.createElement('link'),
script = document.createElement('script');
link.href = 'http://vjs.zencdn.net/c/video-js.css';
link.rel = 'stylesheet';
document.body.appendChild(link);
script.src = 'http://vjs.zencdn.net/c/video.js';
script.onload = function() {
var video = document.createElement('video');
@heldrida
heldrida / jquery.ba-tinypubsub.js
Created March 21, 2012 11:57 — forked from cowboy/HEY-YOU.md
jQuery Tiny Pub/Sub: A really, really, REALLY tiny pub/sub implementation for jQuery.
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011
* http://benalman.com/
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */
(function($) {
var o = $({});
$.subscribe = function() {
o.on.apply(o, arguments);