Skip to content

Instantly share code, notes, and snippets.

@stefansundin
stefansundin / youtube_live.php
Last active December 17, 2015 00:10
PHP script that converts GData feeds for YouTube Live events to human readable feeds.
<?php
/*
https://gist.github.com/stefansundin/5519170
Converts GData feeds for YouTube Live events to human readable feeds.
http://stefansundin.com/blog/476
https://developers.google.com/youtube/2.0/developers_guide_protocol_retrieving_live_events
Use this url to get data for streams that no longer appear in any of the feeds:
https://gdata.youtube.com/feeds/api/users/CHANNELNAME/live/videos/VIDEOID?v=2
It does not appear to contain all of the info though. Replace CHANNELNAME and VIDEOID.
@stefansundin
stefansundin / paypal-gadget.xml
Last active December 22, 2015 22:29
Google Gadget for a PayPal button with an amount text input. Meant to be used on Google Project Hosting.
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="PayPal gadget" author="Stefan Sundin" width="400" height="35"></ModulePrefs>
<UserPref name="business" datatype="string" default_value="8727MAF7NTYRE" />
<UserPref name="item_number" datatype="string" default_value="Donation" />
<UserPref name="amount" datatype="string" default_value="$5.00" />
<UserPref name="return_url" datatype="string" default_value="" />
<UserPref name="return_text" datatype="string" default_value="" />
<Content type="html">
<![CDATA[
@stefansundin
stefansundin / youtube-iframe.xml
Last active January 1, 2016 19:59
Google Gadget to embed YouTube videos.
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="YouTube iframe embed" author="Stefan Sundin" width="640" height="390"></ModulePrefs>
<UserPref name="id" datatype="string" default_value="" />
<UserPref name="width" datatype="string" default_value="" />
<UserPref name="height" datatype="string" default_value="" />
<UserPref name="args" datatype="string" default_value="" />
<Content type="html">
<![CDATA[
<script type="text/javascript">
@stefansundin
stefansundin / flattr-gadget.xml
Last active January 1, 2016 20:09
Google Gadget for Flattr.
<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Flattr button" author="Stefan Sundin" width="55" height="62" scrolling="false"></ModulePrefs>
<UserPref name="url" datatype="string" default_value="" />
<UserPref name="uid" datatype="string" default_value="" />
<UserPref name="title" datatype="string" default_value="" />
<UserPref name="desc" datatype="string" default_value="" />
<UserPref name="cat" datatype="string" default_value="software" />
<UserPref name="lang" datatype="string" default_value="en_GB" />
<UserPref name="tags" datatype="string" default_value="" />
@stefansundin
stefansundin / ltu_username.user.js
Last active January 1, 2016 23:09
Old Greasemonkey/Tampermonkey script, but could be nice to have for people studying at Luleå University of Technology (LTU).
// ==UserScript==
// @name LTU Username
// @namespace https://gist.github.com/stefansundin/
// @homepage https://gist.github.com/stefansundin/8214929
// @downloadURL https://gist.github.com/stefansundin/8214929/raw/ltu_username.user.js
// @version 1.0
// @author Stefan Sundin
// @description Autofill username
// @include https://logon.pub.ltu.se/cgi-bin/logon.cgi
// @include https://fronter.com/ltu/
@stefansundin
stefansundin / 1.gvidcomments.png
Last active January 3, 2016 02:29
Blast from the past. This old Greasemonkey script displayed information about the comments your videos had in your Google Video Status pages, when Google Video was still alive and kicking. R.I.P. Google Video, the only reason people used it was because it didn't have a limit on the video length.
1.gvidcomments.png
@stefansundin
stefansundin / 1.SubRip_batch.md
Last active January 3, 2016 05:19
A patch I made for SubRip 1.50b4 that enables batch processing.

Patch for SubRip batch processing

Based on SubRip 1.50 Beta 4.

Improvements:

  • Batch support.
  • Always save in Unicode.
  • Remember previously used character matrix file (auto-load).
  • Checkbox for auto-running post-OCR correction.
  • Auto-select correct language in post-OCR dialog.
  • Remember the last used save directory.
@stefansundin
stefansundin / aws_maintenance_window.rb
Created April 12, 2016 01:15
Convert AWS maintenance window between timezones.
#!/usr/bin/env ruby
def offset_maintenance_window(w, offset=-7)
days = %w[mon tue wed thu fri sat sun]
if /(?<day_start>[a-z]{3}):(?<hour_start>\d\d):(?<minute_start>\d\d)-(?<day_end>[a-z]{3}):(?<hour_end>\d\d):(?<minute_end>\d\d)/ =~ w
day_start = days.find_index(day_start)
day_end = days.find_index(day_end)
hour_start = hour_start.to_i + offset
minute_start = minute_start.to_i
hour_end = hour_end.to_i + offset
@stefansundin
stefansundin / guess-ytlive-url.py
Last active April 16, 2016 01:42
Python script to hax YouTube Live segments that are no longer accessible via the playlist. See http://stefansundin.com/blog/452#comments
# https://gist.github.com/stefansundin/6261442
# Python 3.x
# Binary search for the correct clen parameter for YouTube live streams, which is useful when a segment is no longer listed in the playlist file (check EXT-X-EARLIEST-MEDIA-SEQUENCE).
# It's quick and dirty. clen is always a multiple of 188 (since it is TS). lmt and dur does not have any impact it seems.
# Usually finds the correct url in about 15 tries.
# See http://stefansundin.com/blog/452#comments
# TODO: add threading to process multiple sequence numbers at the same time.
"""
Regexps to extract clen and dur from a playlist:
@stefansundin
stefansundin / github.rb
Last active May 1, 2016 00:30
Plot GitHub API rate limit usage with gnuplot.
#!/usr/bin/env ruby
# gem install httparty
require "httparty"
trap "SIGINT" do
STDERR.write "\nBye!"
exit 1
end
while true