Skip to content

Instantly share code, notes, and snippets.

Pedro Casaubon xperiments

Block or report user

Report or block xperiments

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View composing-regexps.js
const RE_YEAR = re`(?<year>[0-9]{4})`;
const RE_MONTH = re`(?<month>[0-9]{2})`;
const RE_DAY = re`(?<day>[0-9]{2})`;
const RE_DATE = re`${RE_YEAR}-${RE_MONTH}-${RE_DAY}`;
const matchObj = RE_DATE.exec('1999-12-31');
const year = matchObj.groups.year; // 1999
const month = matchObj.groups.month; // 12
const day = matchObj.groups.day; // 31
@dy
dy / saveAs.js
Created Mar 18, 2017
Open data-uri in new window
View saveAs.js
function saveAs(arrayBuffer, fileName, mime) {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
window.requestFileSystem(window.TEMPORARY, arrayBuffer.byteLength, function(fs) {
fs.root.getFile(fileName, {create: true}, function(fileEntry) {
fileEntry.createWriter(function(writer) {
var dataView = new DataView(arrayBuffer);
var blob = new Blob([dataView], {type: 'font/opentype'});
writer.write(blob);
writer.addEventListener('writeend', function() {
@jherax
jherax / is-private-mode.js
Last active Feb 22, 2020
Detect if the browser is running in Private mode (Promise based)
View is-private-mode.js
/**
* Lightweight script to detect whether the browser is running in Private mode.
* @returns {Promise<boolean>}
*
* Live demo:
* @see https://output.jsbin.com/tazuwif
*
* This snippet uses Promises. If you want to run it in old browsers, polyfill it:
* @see https://cdn.jsdelivr.net/npm/es6-promise@4/dist/es6-promise.auto.min.js
*
View _hidden-scrollbar.sass
/*
* Hidden scrollbar
*/
::-webkit-scrollbar
width: 0px
::-webkit-scrollbar-track-piece
background-color: transparent
-webkit-border-radius: 6px
@tzmartin
tzmartin / embedded-file-viewer.md
Last active Feb 26, 2020
Embedded File Viewer: Google Drive, OneDrive
View embedded-file-viewer.md

Office Web Apps Viewer

('.ppt' '.pptx' '.doc', '.docx', '.xls', '.xlsx')

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

OneDrive Embed Links

@gund
gund / http-interceptor-concept.md
Last active Sep 14, 2017
Concept of Http Interceptor for Angular 2
View http-interceptor-concept.md

First, we need to define interfaces with which we will work:

export interface Interceptable<T extends Interceptor<any, any>> {
  addInterceptor(interceptor: T): Interceptable<T>;
  removeInterceptor(interceptor: T): Interceptable<T>;
  clearInterceptors(interceptors?: T[]): Interceptable<T>;
}

export interface Interceptor<T, D> {
@tizmagik
tizmagik / getLastInMap.js
Created Aug 13, 2016
ES6 Last Item in Map()
View getLastInMap.js
// Since ES6 Map()'s' retain their order of insertion, it can sometimes be useful to get the last item or value inserted:
export const getLastItemInMap = map => Array.from(map)[map.size-1]
export const getLastKeyInMap = map => Array.from(map)[map.size-1][0]
export const getLastValueInMap = map => Array.from(map)[map.size-1][1]
// Obviously getLastKey and getLastValue can reuse getLastItem, but for maximum portability I opted for verbosity.
@robertpenner
robertpenner / employee_salaries.ts
Last active May 14, 2018
Employee Average Salaries | Victor Savkin's Functional TypeScript
View employee_salaries.ts
// https://vsavkin.com/functional-typescript-316f0e003dc6
class Employee {
constructor(public name: string, public salary: number) {}
}
class Department {
constructor(public employees: Employee[]) {}
works(employee: Employee): boolean {
@bennadel
bennadel / app.component.ts
Last active Jun 12, 2017
Experimenting With Dynamic Template Rendering In Angular 2 RC 1
View app.component.ts
// Import the core angular services.
import { Component } from "@angular/core";
// Import the application components and services.
import { DynamicRepeaterComponent } from "./dynamic-repeater.component";
@Component({
selector: "my-app",
directives: [ DynamicRepeaterComponent ],
@davidguttman
davidguttman / split-unspaced-text.js
Created Apr 26, 2016
Split text without spaces into list of words
View split-unspaced-text.js
// port of http://stackoverflow.com/questions/8870261/how-to-split-text-without-spaces-into-list-of-words
var _ = require('lodash')
var fs = require('fs')
var tape = require('tape')
var dictStr = fs.readFileSync(__dirname + '/dump/words-by-freq.txt', 'utf8')
var wordsByFreq = dictStr.split('\n')
var maxWord = 0
You can’t perform that action at this time.