Skip to content

Instantly share code, notes, and snippets.

View dpogorzelski's full-sized avatar

Dawid Pogorzelski dpogorzelski

View GitHub Profile
<Location /auth/foo/callback>
AuthType shibboleth
ShibRequireSession On
ShibRequestSetting entityID https://foo.shib.idp
require valid-user
</Location>
<Location /auth/bar/callback>
AuthType shibboleth
ShibRequireSession On
module OmniAuth::Strategies
class Foo < Shibboleth
def name
:foo
end
end
class Bar < Shibboleth
def name
:bar
@dpogorzelski
dpogorzelski / decode
Created October 15, 2013 12:46
Client-side File Encryption: Decode
openssl enc -d -aes256 -a -in <encryptedfile> |base64 --decode > <outputfile>
@dpogorzelski
dpogorzelski / controllers.js
Last active December 25, 2015 14:29
Client-side File Encryption: Frontend
$scope.onFile = function(files) {
//onFile goes through each file inside the files array, encrypts them and
//pushes the blobs to an array
for (var i = 0; i < files.length; i++) {
Crypt.bury(files[i], $scope.key.value, function(blob) {
$scope.$apply(function() {
$scope.files.push(blob)
});
});
}
@dpogorzelski
dpogorzelski / services.js
Last active December 25, 2015 14:29
Client-side File Encryption: Frontend
//This is the service which is injected inside the controller and encrypts each
//file in the array generated by the directive
services.service('Crypt', [
function() {
this.bury = function(file, key, callback) {
// we need a new FileReader instance to read the file's content
var reader = new FileReader();
//we read the content as array buffer so we can handle binary data
//too
reader.readAsArrayBuffer(file);
@dpogorzelski
dpogorzelski / directives.js
Created October 15, 2013 12:43
Client-side File Encryption: Frontend
//This directive handles multiple file selection and makes them available
// as an array to the onFile() function inside the controller
directives.directive('fileselect', ['$parse',
function($parse) {
return function(scope, elem, attr) {
var fn = $parse(attr['fileselect']);
elem.bind('change', function(evt) {
var files = [];
var fileList = evt.target.files;
for (var i = 0; i < fileList.length; i++) {
@dpogorzelski
dpogorzelski / server.js
Last active December 25, 2015 14:29
Client-side File Encryption: Backend
app.post('/file', function(req, res) {
//We create a write stream which will save the file to gridfs.
//"gridfs-stream" is great at this.
var writestream = gfs.createWriteStream({
filename: req.files.file.name
});
//fs.createReadStream() will read the file uploaded to tmp directory and
//pipe it to the write stream.
@dpogorzelski
dpogorzelski / directives.js
Created August 27, 2013 08:16
Twitter share button as AngularJS directive.
directives.directive('twitter', [
function() {
return {
link: function(scope, element, attr) {
setTimeout(function() {
twttr.widgets.createShareButton(
attr.url,
element[0],
function(el) {}, {
count: 'none',
@dpogorzelski
dpogorzelski / controllers.js
Created August 22, 2013 15:48
Simplified version of "angular-file-upload" directive. Removed support for old browsers. (original version: https://github.com/danialfarid/angular-file-upload)
"use strict";
app.controller('mainCtrl', ['$scope', '$http',
function($scope, $http) {
$scope.onFileSelect = function(files) {
console.log(files);
for (var i = 0; i < files.length; i++) {
var file = files[i];
$http.uploadFile({
url: 'api/file',
@dpogorzelski
dpogorzelski / Dockerfile
Created August 17, 2013 11:37
Docker file to build and run a Sinatra project
# DOCKER-VERSION 0.5.3
FROM ubuntu:12.10
RUN apt-get update
RUN apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion pkg-config wget -y
RUN wget ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p247.tar.gz
RUN tar xvf ruby-2.0.0-p247.tar.gz
RUN cd ruby-2.0.0-p247; ./configure; make install
RUN gem update --system
RUN gem install bundler
ADD . /src