Skip to content

Instantly share code, notes, and snippets.

View mataspetrikas's full-sized avatar
🤔
busy busy

Matas Petrikas mataspetrikas

🤔
busy busy
View GitHub Profile
@mataspetrikas
mataspetrikas / importzendesk.js
Created August 28, 2018 09:27
A Node.js script for importing existing email tickets to Zendesk
// npm install request --save
var request = require('request');
var fs = require('fs');
// update these with your auth values
var username = 'xxx@abc.io';
var userpassword = 'xxxx';
var workspace = 'oursupport';
var importtags = [ "importedticket", "inbox-info"];
enum BooType {
case play
}
protocol FooDelegate {
func onBoo(boo: BooType)
}
class Foo {
var delegate: FooDelegate?
@mataspetrikas
mataspetrikas / gist:2301090
Created April 4, 2012 13:36
WordPress code: HTML5 widget with sharing disabled
[soundcloud url="http://api.soundcloud.com/tracks/1460857?sharing=false" iframe="true" /]
@mataspetrikas
mataspetrikas / gist:2300296
Created April 4, 2012 10:45
Check if the DOM node is visible in the viewport
function elementInViewport(el) {
var rect = el.getBoundingClientRect()
return rect.top < (window.innerHeight || document.body.clientHeight) && rect.left < (window.innerWidth || document.body.clientWidth);
}
// and then you can use it:
alert(elementInViewport(document.getElementById('inner')));
// or
alert(elementInViewport($('#inner')[0]));
`
@mataspetrikas
mataspetrikas / gist:1779157
Created February 9, 2012 10:34
Create a SoundCloud widget from the id passed in the url
// You will need jQuery to be available on your page
// the widget will be written into HTML element with id="player" or some other DOM element that $playerContainer will point to
// the url format should be http://example.com/mytracks?track_id=3223234 or http://example.com/mytracks?track_url=http://soundcloud.com/matas/hobnotropic
$(function(){
var params = location.search,
trackId = (params.match(/track_id=(\d+)/)||[])[1],
trackUrl = (params.match(/track_url=(.+?)(&|$)/)||[])[1],
$playerContainer = $('#player');
if (trackId) {
trackUrl = 'http://api.soundcloud.com/tracks/' + trackId;
@mataspetrikas
mataspetrikas / gist:1723694
Created February 2, 2012 14:24
Converting HTML links to SoundCloud widgets using JQuery
// if you have a link in your HTML that points to a sound: <a href="http://soundcloud.com/matas/hobnotropic">My Track</a>
// it will convert them to our new HTML5 widgets
$('a[href*="soundcloud.com"]').each(function(){
var $link = $(this);
$.getJSON('http://soundcloud.com/oembed?format=js&url=' + $link.attr('href') + '&iframe=true&callback=?', function(response){
$link.replaceWith(response.html);
});
});
@mataspetrikas
mataspetrikas / gist:1509934
Created December 22, 2011 11:10
control next and previous tracks in the soundcloud custom player
function getNextTrack(node) {
var $player = $(node).closest('.sc-player'),
$nextItem = $('.sc-trackslist li.active', $player).next('li');
// try to find the next track in other player
if(!$nextItem.length){
$nextItem = $player.nextAll('div.sc-player:first').find('.sc-trackslist li:first');
}
return $nextItem;
};
@mataspetrikas
mataspetrikas / gist:1027211
Created June 15, 2011 14:23
favorites player
$('<a href="http://soundcloud.com/matas/favorites">My Favorites</a>').scPlayer({
randomize: true,
autoPlay: true
});
@mataspetrikas
mataspetrikas / gist:1024911
Created June 14, 2011 13:38
Mockjax remote jsonp failure
asyncTest('Response returns jsonp', function() {
$.mockjax({
url: 'http://example.com/jsonp*',
contentType: 'text/json',
proxy: 'test_jsonp.js'
});
window.abcdef123456 = function(json) {
ok( true, 'JSONP Callback executed');
deepEqual(json, { "data" : "JSONP is cool" });
};
@mataspetrikas
mataspetrikas / gist:986383
Created May 23, 2011 08:06
show additional titile in the custom player
append this to your script:
// update additional title
$(document).bind('onPlayerTrackSwitch.scPlayer', function(event, track) {
var $player = $(event.target);
$('.sc-inline-title', $player).remove();
$('<p class="sc-inline-title">' + track.title +'</p>').appendTo($('.sc-scrubber', $player));
});
or hack the sc-player directly (will be overwritten with the next update)