Skip to content

Instantly share code, notes, and snippets.

Avatar
🤔
busy busy

Matas Petrikas mataspetrikas

🤔
busy busy
View GitHub Profile
@mataspetrikas
mataspetrikas / importzendesk.js
Created Aug 28, 2018
A Node.js script for importing existing email tickets to Zendesk
View importzendesk.js
// 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"];
View .swift
enum BooType {
case play
}
protocol FooDelegate {
func onBoo(boo: BooType)
}
class Foo {
var delegate: FooDelegate?
@mataspetrikas
mataspetrikas / gist:2301090
Created Apr 4, 2012
WordPress code: HTML5 widget with sharing disabled
View gist:2301090
[soundcloud url="http://api.soundcloud.com/tracks/1460857?sharing=false" iframe="true" /]
@mataspetrikas
mataspetrikas / gist:2300296
Created Apr 4, 2012
Check if the DOM node is visible in the viewport
View gist:2300296
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 Feb 9, 2012
Create a SoundCloud widget from the id passed in the url
View gist:1779157
// 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 Feb 2, 2012
Converting HTML links to SoundCloud widgets using JQuery
View gist:1723694
// 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 Dec 22, 2011
control next and previous tracks in the soundcloud custom player
View gist:1509934
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;
};
View gist:1027211
$('<a href="http://soundcloud.com/matas/favorites">My Favorites</a>').scPlayer({
randomize: true,
autoPlay: true
});
@mataspetrikas
mataspetrikas / gist:1024911
Created Jun 14, 2011
Mockjax remote jsonp failure
View gist:1024911
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
show additional titile in the custom player
View gist:986383
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)