Skip to content

Instantly share code, notes, and snippets.

Razvan Caliman oslego

Block or report user

Report or block oslego

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
@oslego
oslego / StyleSheetArrayProxy.js
Created Dec 9, 2019
StyleSheetArray implementation with Proxy and Reflect
View StyleSheetArrayProxy.js
// https://github.com/WICG/construct-stylesheets/issues/45#issuecomment-522879888
'use strict';
function isArrayIndex(string) {
if (typeof string !== 'string') {
return false;
}
const number = Number(string);
return Number.isSafeInteger(number)
@oslego
oslego / gist:f13e136ffeaa6174289a
Last active Jan 3, 2019 — forked from sl4m/gist:5091803
create self-signed certificate for localhost
View gist:f13e136ffeaa6174289a
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@oslego
oslego / Guide to CSS Regions.md
Last active Jan 16, 2018
Short guide to using CSS Regions
View Guide to CSS Regions.md

Guide to CSS Regions

Introduction

CSS Regions are a mechanism used in web pages to separate content from its layout. Regions can be used to visually flow content from one element to another regardless of the content's original location in the DOM tree.

Concepts

View elementsFromPoint.js
//
// returns a list of all elements under the cursor
//
function elementsFromPoint(x,y) {
var elements = [], previousPointerEvents = [], current, i, d;
// get all elements via elementFromPoint, and remove them from hit-testing in order
while ((current = document.elementFromPoint(x,y)) && elements.indexOf(current)===-1 && current != null) {
// push the element and its current style
@oslego
oslego / String.isBalanced.js
Created Aug 4, 2017
Method that returns true when a string is balanced and false otherwise.
View String.isBalanced.js
/*
Task:
Given an input string return true if the string is balanced, otherwise return false.
A string is balanced when every opening bracket "{", square bracket "[", and parenthesis "("
has a matching closing character.
*/
const string = "{[()]}";
(function(input){
@oslego
oslego / javascript_multiton.js
Created Jun 3, 2011
JavaScript Multiton Example
View javascript_multiton.js
/*
Use, reuse but don't abuse!
Author: Razvan Caliman (razvan.caliman@gmail.com)
This is an example of a "Multiton" pattern;
Create a fixed number of instances of a class.
Use "lazy instantiation" to create objects only if needed.
If the maximum number of instances has been reached, return a random one from the ones created.
*/
@oslego
oslego / recursive_toLargestUnit.js
Created Dec 31, 2016
Get size on disk by highest order of magnitude using recursion.
View recursive_toLargestUnit.js
// From https://ponyfoo.com/articles/var-let-const
function toLargestUnit (value, unit = `MB`) {
const units = [`MB`, `GB`, `TB`]
const i = units.indexOf(unit)
const nextUnit = units[i + 1]
if (value >= 1024 && nextUnit) {
return toLargestUnit(value / 1024, nextUnit)
}
return { value, unit }
}
@oslego
oslego / pr.md
Created Jun 11, 2016 — forked from bgrins/pr.md
Checkout github pull requests locally
View pr.md

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@oslego
oslego / alternative_switch.js
Created Jan 20, 2016
Alternative JS solution to `switch` statement or suite of `if` statements.
View alternative_switch.js
/*
Alternative solution to switch statement or a suite of if statements
using an object literal in JS to store cases.
if (type == "save") { }
if (type == "delete") { }
*/
function operation(type, opts) {
var handler = {
You can’t perform that action at this time.