Skip to content

Instantly share code, notes, and snippets.

View morales2k's full-sized avatar
🏠
Working from home

Jorge Morales morales2k

🏠
Working from home
View GitHub Profile
@morales2k
morales2k / default.sublime-keymap
Last active December 20, 2015 05:49
Sublime Text 2 reindent full document shortcut keybinding. This gist is to be added to user keybindings to set f12 key to issue the reindent command to the complete document instead of doing it to a single line as it does when doing it from the menu. One normally selects all the document before doing this command from the menu, with the argument…
[
{
"keys": ["f12"],
"command": "reindent",
"args": {
"single_line": false
}
}
]
@morales2k
morales2k / gist:6193580
Last active December 20, 2015 20:49
Google Analytics function for custom events for analytics.js Use it anyway you want, from simply adding onclick attribute to an element other than <a> to track a click event. Easily customizable to make it track other stuff besides event hitType, or click action for that matter. See analytics.js documentation https://developers.google.com/analyt…
/*!
* Tracking function to be used with the new analytics.js (i,s,o,g,r,a,m) snippet
* @param el string Identifier for the tracking click event
* @author Jorge L. Morales (EffectiX.Net)
* @return void
*/
function gaTrack(el){
ga('send',
{
'hitType': 'event',
@morales2k
morales2k / gaq.push
Created November 7, 2013 13:45
Google Analytics -> One push, multiple UA tracking codes.
_gaq.push(
['_setAccount', 'UA-XXXXX-1'],
['_trackPageview'],
['b._setAccount', 'UA-XXXXX-2'],
['b._trackPageview']
);
@morales2k
morales2k / make_links
Created April 18, 2014 18:06
Function to make links inside blobs of text by matching urls and replacing them with the links... includes support for cyrilic characters... still has some quirks to work out... but it works on pretty much all cases as far as I have tested it... feel free to suggest improvements! :)
@morales2k
morales2k / posts_from_page.php
Last active November 18, 2020 17:06
Get Facebook public posts from a page. This requires facebook's php sdk, and a properly registered app.
<?php
function make_links($text, $class='', $target='_blank'){
return preg_replace('!((http\:\/\/|ftp\:\/\/|https\:\/\/)|www\.)([-a-zA-Zа-яА-Я0-9\~\!\@\#\$\%\^\&\*\(\)_\-\=\+\\\/\?\.\:\;\'\,]*)?!ism', '<a class="'.$class.'" href="//$3" target="'.$target.'">$1$3</a>', $text);
}
define("APP_ID", 'xxxxxxxxxxxxxxxxxxx');
define("APP_SECRET",'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx');
define("PAGE_ID",'elnuevodia');
$config = array(
'appId' => APP_ID,
@morales2k
morales2k / getCookie.js
Created May 29, 2014 18:05
doSomething in js based on wether or not a cookie is set with the getCookie function
function getCookie(name) {
var dc = document.cookie;
var prefix = name + "=";
var begin = dc.indexOf("; " + prefix);
if (begin == -1) {
begin = dc.indexOf(prefix);
if (begin != 0) return null;
}
else
{
@morales2k
morales2k / jquery-sidr.js
Created July 8, 2014 17:31
The jquery-sidr fix that made it work for me in all browsers. Try it out and see if it helps!
/*
* Sidr
* https://github.com/artberri/sidr
*
* Copyright (c) 2013 Alberto Varela
* Licensed under the MIT license.
*/
;(function( $ ){
@morales2k
morales2k / print_r snippet.sublime-snippet
Created July 24, 2014 20:36
Snippet for sublime text for quickly producing print_r blocks that are pretty.
<snippet>
<content><![CDATA[
echo '<pre>'; print_r(${1:ARRAY}); echo '</pre>';
]]></content>
<description>PHP: Pretty print_r</description>
<scope>source.php</scope>
<tabTrigger>prnt</tabTrigger>
</snippet>
@morales2k
morales2k / preg_match magic.php
Last active August 29, 2015 14:04
Youtube regex to extract video id from most youtube urls... from stack overflow answer: http://stackoverflow.com/a/17030234/1591301
$yturl = 'http://youtu.be/0f4qZkd4npM';
/*
other possible urls...
youtube.com/v/vidid
youtube.com/vi/vidid
youtube.com/?v=vidid
youtube.com/?vi=vidid
youtube.com/watch?v=vidid
youtube.com/watch?vi=vidid
youtu.be/vidid
@morales2k
morales2k / videoData.class.php
Created July 31, 2014 16:25
Get youtube video info and embed code from input youtube url. Can be easily modified to use different "part" queries... but I'm doing just the snippet and player ones here...
<?php
class videoData{
static $videoId = '';
static $videoData = array();
static private $apiKey = '[YOUR_API_KEY_HERE]';
static $url = 'https://www.googleapis.com/youtube/v3/videos?id=@@VIDEOID@@&part=snippet,player&key=@@APIKEY@@';
static $lastURL = '';
static function getIdFromURL($url){