Skip to content

Instantly share code, notes, and snippets.

View Offirmo's full-sized avatar
⚔️
Coding a RPG… (as a hobby)

Offirmo Offirmo

⚔️
Coding a RPG… (as a hobby)
View GitHub Profile
@Offirmo
Offirmo / rx-observable.js
Last active May 26, 2017 03:02
[Observable] #tags:JavaScript,RxJS
const obs$ = Rx.Observable.create((observer) => {
observer.next(1)
// either:
observer.error(new Error('404'))
observer.complete()
})
observable.subscribe(
value => console.log(value),
err => console.error(value),
@Offirmo
Offirmo / snow.js
Created July 27, 2017 05:43
[Snow] #JavaScript
// https://github.com/Offirmo/blog/blob/gh-pages/tosort/javascript-daily/mod-floating.md
const floating = require('floating.js)
floating({
content: '<span style="color: snow">❄</span>',
number: 25,
direction: 'reverse',
size: [0.5, 2.5],
})
@Offirmo
Offirmo / umd.js
Last active August 29, 2017 01:33
[Improved UMD template to work with webpack 2] #JavaScript #umd #webpack
// Iterating on the UMD template from here:
// https://github.com/umdjs/umd/blob/master/templates/returnExportsGlobal.js
// But experimentally improving it so that it works for webpack 2
// UMD template from https://gist.github.com/Offirmo/ec5c7ec9c44377c202f9f8abcacf1061#file-umd-js
(function (root, factory) {
var LIB_NAME = 'Foo'
if (typeof define === 'function' && define.amd) {
@Offirmo
Offirmo / navigation.js
Last active October 5, 2017 05:59
[Intercepting navigation in JavaScript] #JavaScript #browser #growth
function hookNavigationEvent(onNavigate) {
// always provide a full location object to the final callback
function uniformizedOnNavigate(locationOrUrl) {
try {
const location = (typeof locationOrUrl === 'string')
? new URL(
locationOrUrl[0] === '/' // relative
? document.location.origin + locationOrUrl
: locationOrUrl
@Offirmo
Offirmo / index.html
Last active October 23, 2017 06:32
[file imports in HTML] #html #JavaScript #css #browser
<link rel="stylesheet" type="text/css" href="https://cdn.rawgit.com/alertifyjs/alertify.js/v1.0.11/dist/css/alertify.css" />
<script src="https://cdn.rawgit.com/alertifyjs/alertify.js/v1.0.11/src/js/alertify.js"></script>
<script src="https://unpkg.com/floating.js@2.6.3/floating.js"></script>
<script>
console.log('hello world')
</script>
<noscript>Your browser either does not support JavaScript, or has it turned off.</noscript>
@Offirmo
Offirmo / es6.js
Last active March 28, 2018 14:12
[rare ES6 stuff I forget all the time] #JavaScript
// imports
import { Random, Engine } from '@offirmo/random'
import {
State as MetaState,
factory as meta_state_factory,
} from '@oh-my-rpg/state-meta'
// http://www.benmvp.com/learning-es6-enhanced-object-literals/
return {
@Offirmo
Offirmo / intercept.js
Last active June 21, 2018 00:23
[Function call interception (wrapping)] #JavaScript #growth
// new
return (...args) => {
try {
return handler.call(this, ...args);
} catch(e) {
return this.onError(e);
}
};
// old school
@Offirmo
Offirmo / lib.js
Last active December 2, 2018 07:51
[browser micro-lib] #JavaScript #browser #growth #frontend
https://github.com/terkelg/facon
// in Offirmo monorepo!
function poll(predicate, options) {
// early check to save an initial poll period
let result = predicate();
if (result)
return Promise.resolve(result);
@Offirmo
Offirmo / marky.ts
Last active December 2, 2018 07:51
[User timing measurement with marky] #TypeScript #JavaScript #frontend
import 'marky'
const user_timing_measurement = (window as any).user_timing_measurement
user_timing_measurement.mark('bootstrap')
...
user_timing_measurement.stop('bootstrap')
// https://www.html5rocks.com/en/tutorials/webperformance/basics/
@Offirmo
Offirmo / BEM.css
Last active December 2, 2018 07:53
BEM #css #frontend
/*
https://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/
http://bradfrost.com/blog/post/atomic-web-design/#atoms
zqsmm.qiniucdn.com/data/20110511083224/index.html
*/
.block {}
.block__element {}
.block--modifier {}