Skip to content

Instantly share code, notes, and snippets.

@demelziraptor
demelziraptor / Readme.md
Last active August 29, 2015 14:03
Pretty rake arguments

Output:

$ rake test_task test hello whatsup?
["test", "hello", "whatsup?"]
@demelziraptor
demelziraptor / get-sharepoint-access-token.py
Created February 16, 2014 19:34
Code example to get a Sharepoint Access Token to use with the Sharepoint REST API using a python 3 provider-hosted Sharepoint App (using cherrypy). This code takes the data POSTed to it when you click on the app in Sharepoint, and authenticates using OAuth to get the access token. To use the Sharepoint REST API with OAuth, the app needs to be re…
import cherrypy
import jwt
import urllib.parse, urllib.request
import json
SPSECRET = 'gpYucHkODHOv6JxZJ89Kihl9ncTiTrUCAbOaF1N6uJE='
cherrypy.config.update({'server.socket_port': 3005,
'server.ssl_module': 'builtin',
'server.ssl_certificate': 'cert.pem',
@demelziraptor
demelziraptor / add_devise_columns_to_user.rb
Created May 23, 2012 23:12
Devise API register and sign in using tokens
class AddDeviseColumnsToUser < ActiveRecord::Migration
def self.up
change_table :users do |t|
t.string :authentication_token
end
end
def self.down
change_table :users do |t|
t.remove :authentication_token
end
@demelziraptor
demelziraptor / sc-dl-min.js
Created May 22, 2012 10:30 — forked from duncanbeevers/sc-dl-min.js
Bookmarklet that generates download link for a Soundcloud upload
(function(a){function b(a){var b=$.helpers,f=b.getPlayerTrack(b.getPlayerNode(a)),g=a.find(".actionbar");if(!f){return}if(a.hasClass("player")){if(g.length){c(f,g)}else{d(f,a)}}else{e(f,a)}}function c(a,b){var c=b.find(".download, .mock-download");if(!c.length||c.hasClass("disabled")){var d=$('<a class="pl-button mock-download"><span>Download</span></a>').css({backgroundImage:"url(http://soundcloud.com/images/icons_mini.png?unicorn26)",backgroundRepeat:"no-repeat",backgroundPosition:"-77px -236px",paddingLeft:"18px"}).attr("download",a.title+".mp3");b.find(".primary").append(d);d.attr("href",a.streamUrl)}}function d(a,b){var d=null;if(b.hasClass("nano")){d=f(b.closest(".track-title").find(".track")).css({marginLeft:"18px"})}else if(b.hasClass("small")){d=f(b.find(".container"))}if(d){c(a,d)}}function e(a,b){var c=b.find(".actions"),d=c.find(".download");if(!d.length){c.prepend('<a href="'+a.streamUrl+'" class="download pl-button" download="'+a.title+'" title="'+a.title+'">Download track</a>')}}function f(a){v
@demelziraptor
demelziraptor / gitlab-graph-no-master
Created May 21, 2012 14:53
Fix gitlab network graph without master branch
Gitlab uses Grit for the network graph, and Grit relies on the master branch for this functionality. Without a master branch the graph shows up blank, however, you can get it to show the graph for your default branch only (instead of all branches as it would normally show) by changing the following line in lib/graph_commit.rb:
commits = Grit::Commit.find_all(@repo, nil, {:max_count => 650})
With this:
commits = Grit::Commit.find_all(@repo, project.root_ref, {:max_count => 650})
@demelziraptor
demelziraptor / gitlab-zip.rb
Created May 17, 2012 09:28
Dirty hack to get gitlab archive download to use zip rather than tar.gz
def archive
unless can?(current_user, :download_code, @project)
render_404 and return
end
ref = params[:ref] || @project.root_ref
commit = @project.commit(ref)
render_404 and return unless commit
# Build file path