Skip to content

Instantly share code, notes, and snippets.

@kukula
kukula / hello_world.md
Last active June 29, 2017 18:38
web "hello world".

Sinatra - Ruby

require 'sinatra'

get '/' do
  'Hello world!'
end
@malko
malko / urlBase64ToUint8Array.js
Created March 31, 2017 12:58
used in pushManager.Subscribe to correctly encode the key to a Uint8Array
function urlBase64ToUint8Array(base64String) {
const padding = '='.repeat((4 - base64String.length % 4) % 4);
const base64 = (base64String + padding)
.replace(/\-/g, '+')
.replace(/_/g, '/')
;
const rawData = window.atob(base64);
return Uint8Array.from([...rawData].map((char) => char.charCodeAt(0)));
}
@nhagen
nhagen / PromisAllWithFails.js
Last active November 15, 2022 18:11
Wait until all promises have completed even when some reject, with Promise.all
var a = ["sdfdf", "http://oooooolol"],
handleNetErr = function(e) { return e };
Promise.all(fetch('sdfdsf').catch(handleNetErr), fetch('http://invalidurl').catch(handleNetErr))
.then(function(sdf, invalid) {
console.log(sdf, invalid) // [Response, TypeError]
})
.catch(function(err) {
console.log(err);
})
@g3d
g3d / gist:6ce15fb55ec6db8a60c3
Last active August 29, 2015 14:17
xlsx parsing in ruby
XLSX file, 1.5 Mb, 10 000 rows
==================================
Benchmark.measure { ::Creek::Book.new(import.import_file.read.path).sheets.first.rows.first }
<Benchmark::Tms:0x0000010eb1b200
@cstime=0.0,
@cutime=0.0,
@label="",
@real=83.360489,
@fehmicansaglam
fehmicansaglam / Application.java
Created February 9, 2012 18:50
Accept range header and write a partial content to the response with Play! Framework.
public static void downloadFile(final Long fileId) throws IOException {
response.setHeader("Accept-Ranges", "bytes");
notFoundIfNull(fileId);
File underlyingFile = ... //load file
String fileName = ...//name of the file
Header rangeHeader = request.headers.get("range");
if (rangeHeader != null) {
throw new PartialContent(underlyingFile, fileName);