Skip to content

Instantly share code, notes, and snippets.

View adalbertopita's full-sized avatar

Adalberto Pita adalbertopita

View GitHub Profile
@adalbertopita
adalbertopita / Youtube thumb function
Last active October 2, 2015 05:58
PHP: Youtube thumb function
<?php
function thumbYoutube($link){
$id = substr($link,31,11);
$url = 'http://i' . rand(1, 4) .'.ytimg.com/vi/'. $id .'/hqdefault.jpg';
return $url;
}?>
@adalbertopita
adalbertopita / usage.php
Created March 24, 2012 16:44
Wordpress: Add to <head>
<?php
function add_head($function_to_add, $priority = 10, $accepted_args = 1) {
add_action("wp_head", $function_to_add, $priority, $accepted_args);
} ?>
@adalbertopita
adalbertopita / gist:2185027
Created March 24, 2012 16:51
PHP: Getting last photos on Flickr with phpflickr
<?php
//http://phpflickr.com/
require_once("incs/phpflickr.php");
$f = new phpFlickr("afedae4d8b7b983cebea0af35b0f3f21");
$usuario = '67844506@N07';
$recent = $f->people_getPublicPhotos($usuario,NULL,NULL,12,1);
foreach ($recent['photos']['photo'] as $foto) {
echo "<li><a rel='example_group' href='http://farm".$foto['farm'].".static.flickr.com/".$foto['server']."/".$foto['id']."_".$foto['secret']."_z.jpg'>
@adalbertopita
adalbertopita / gist:2258887
Created March 31, 2012 03:05
Wordpress: Catch_that_image()
<?php function catch_that_image() {
global $post, $posts;
$first_img = '';
ob_start();
ob_end_clean();
$output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
$first_img = $matches [1] [0];
if(empty($first_img)){ //Defines a default image
$first_img = "";
@adalbertopita
adalbertopita / gist:2279839
Created April 2, 2012 01:03
Wordpress: Listar posts relacionados by Tags
<?php
//$post->ID = Post atual
$tags = wp_get_post_tags($post->ID);
if($tags) :
$tag_ids = array();
foreach($tags as $individual_tag) $tag_ids[] = $individual_tag->term_id;
$args=array(
'tag__in' => $tag_ids,
'post__not_in' => array($post->ID),
'showposts'=>6,
@adalbertopita
adalbertopita / Preferences.sublime-settings
Created February 26, 2015 20:36
Config File for Sublime
{
"bold_folder_labels": false,
"caret_extra_width": 2,
"color_scheme": "Packages/Theme - Spacegray/base16-ocean.dark.tmTheme",
"detect_slow_plugins": false,
"draw_white_space": "all",
"enable_tab_scrolling": false,
"fade_fold_buttons": false,
"file_selected_text": true,
"flatland_sidebar_tree_xsmall": false,
@adalbertopita
adalbertopita / getTopVideos.js
Last active August 29, 2015 14:16
Get Top Videos Youtube
var yt = (function() {
return {
init: function() {
this.feed('US');
this.filter();
this.countryName('US');
},
feed: function(country){
$.getJSON('http://gdata.youtube.com/feeds/api/standardfeeds/'+country+'/most_popular?time=all_time&v=2&alt=json', function(data) {
@adalbertopita
adalbertopita / Gruntfile.js
Last active August 29, 2015 14:18
Gruntfile.js
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
files: ['Gruntfile.js', '_/js/*.js'],
options: {
globals: {
jQuery: true
@adalbertopita
adalbertopita / doStuff.js
Created April 17, 2015 00:45
immediately executed function:
(function doStuff() {
  $.ajax({
url: "http://localhost/auth.js",
dataType : "json",
error: function(xhr, status, errorThrown){
},
success: function(data){
console.log(data.auth);
if(!data.auth){
window.location = "http://www.google.com/";
google.maps.event.addListenerOnce(map, 'idle', function(){
// do something only the first time the map is loaded
});