Skip to content

Instantly share code, notes, and snippets.

View slav123's full-sized avatar

Slawomir Jasinski slav123

View GitHub Profile
@slav123
slav123 / new_gist_file
Created June 10, 2013 08:34
video sitemap generator
http://www.canadaseozone.com/web-services/xml-video-sitemap-generator/#show
//npm install b64url
//A signed_request for testing:
//WGvK-mUKB_Utg0l8gSPvf6smzacp46977pTtcRx0puE.eyJhbGdvcml0aG0iOiJITUFDLVNIQTI1NiIsImV4cGlyZXMiOjEyOTI4MjEyMDAsImlzc3VlZF9hdCI6MTI5MjgxNDgyMCwib2F1dGhfdG9rZW4iOiIxNTI1NDk2ODQ3NzczMDJ8Mi5ZV2NxV2k2T0k0U0h4Y2JwTWJRaDdBX18uMzYwMC4xMjkyODIxMjAwLTcyMTU5OTQ3NnxQaDRmb2t6S1IyamozQWlxVldqNXp2cTBmeFEiLCJ1c2VyIjp7ImxvY2FsZSI6ImVuX0dCIiwiY291bnRyeSI6ImF1In0sInVzZXJfaWQiOiI3MjE1OTk0NzYifQ
function parse_signed_request(signed_request, secret) {
encoded_data = signed_request.split('.',2);
// decode the data
sig = encoded_data[0];
json = base64url.decode(encoded_data[1]);
data = JSON.parse(json); // ERROR Occurs Here!
@slav123
slav123 / .sh
Created June 12, 2013 03:26
grunt path Mac OS X
PATH=$PATH:/usr/local/share/npm/bin/
@slav123
slav123 / new_gist_file
Created June 19, 2013 06:38
MC and PEM keys
Put the following into ~/.ssh/config:
Host ec2.xxx.compute.amazonaws.com
User ec2-user
IdentityFile /path/to/the/my.pem
@slav123
slav123 / current-url.php
Created June 19, 2013 11:10
wordpress, current url
<?php
global $wp;
$current_url = add_query_arg( $wp->query_string, '', home_url( $wp->request ) );
?>
@slav123
slav123 / set-values.js
Created June 23, 2013 04:57
set form values, from json
$.each(data, function(name, val){
var $el = $('#listify_form [name="'+name+'"]'),
type = $el.attr('type');
switch(type){
case 'checkbox':
$el.attr('checked', 'checked');
break;
case 'radio':
$el.filter('[value="'+val+'"]').attr('checked', 'checked');
@slav123
slav123 / new_gist_file
Created July 9, 2013 05:07
do short code on wordpress
<?php
echo do_shortcode( '[salesforce form="'.$form_id.'"]' );
@slav123
slav123 / functions.php
Created September 10, 2013 11:21
downgrade jQuery on wordpress
<?php
// Downgrade to jQuery given version
function downgrade_jquery() {
global $wp_scripts;
// We want to use version 1.8.3 of jQuery, but it may break something in the admin so we only load it on the actual site.
if ( !is_admin() ) :
wp_deregister_script('jquery');
wp_register_script('jquery', '//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js', false, '1.8.2');
endif;
@slav123
slav123 / serializeObject.js
Created September 15, 2013 11:38
form - serialize to Object
$.fn.serializeObject = function()
{
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
@slav123
slav123 / populate_form.js
Created September 15, 2013 11:46
populate form with json object via JavaScript
function populate_form(data, form) {
$.each( data, function(name, value) {
// grab input
var input = $(":input[name='" + name + "']:not(:button,:reset,:submit,:image)", form );
input.val( ( !$.isArray( value ) && ( input.is(':checkbox') || input.is(':radio') ) ) ? [ value ] : value );
// populate select value
var select = $(":input[type='select']", form );
if (select) {