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 / gist:4713286
Last active September 25, 2017 23:57
[Some C++] #c++
#include <iostream>
#include <functional>
class MemFunTest
{
public:
bool test0()
{
std::cout << "[" << this <<"-test0 called]" << std::endl;
return false;
@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 / simple_di.ts
Last active September 21, 2017 06:41
[Simple TypeScript dependency injection] #tags: TypeScript
import { foo } from '../libs/foo'
import { bar } from './libs/bar'
interface InjectableDependencies {
logger: Console
foo: typeof foo
}
const defaultDependencies: InjectableDependencies = {
logger: console,
@Offirmo
Offirmo / hackerrank.js
Last active February 22, 2024 04:06
[JS Hacker Rank useful snippets] #JavaScript #competition
const _ = require('lodash')
/////// REDUCE ///////
res = .reduce((acc, val) => {
return acc + val
}, 0)
err = decorators.reduce((err, decorator) => {
return decorator(err)
}, err)
@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 / 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 / js.js
Last active January 29, 2024 10:09
[rare JavaScript stuff I forget all the time] #JavaScript
// null coalescings https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Nullish_coalescing
foo = foo ?? 42
foo ??= 42
// optional chaining https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining
dog?.name
dog?.[name]
hello?.(target)
@Offirmo
Offirmo / proxy-function.ts
Last active February 18, 2022 11:58
[proxy function in TypeScript] #tags: TypeScript
/**
* Conveniently proxy functions instead of storing the value and applying it yourself.
*
* proxyFunction(someApiFunction, (args, callOriginalFunction) => {
* if (whateverYouWant) {
* return 'custom value'
* // Never call the original
* }
*
*
@Offirmo
Offirmo / intro.bash
Last active September 25, 2017 12:35
[Basic Bash script] #bash
#!/usr/bin/env bash
## https://stackoverflow.com/questions/31313305/portably-trapping-err-in-shell-script
## http://mywiki.wooledge.org/BashFAQ/105
set -o errexit
## current shell can be tested with this:
## https://stackoverflow.com/a/11097703/587407
echo "* current shell : '`ps -p $$ -ocomm=`'"
@Offirmo
Offirmo / deep_destructuring.js
Last active February 20, 2024 08:45
[JS deep destructuring] #JavaScript
// from https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Op%C3%A9rateurs/Affecter_par_d%C3%A9composition
var metadata = {
title: "Scratchpad",
translations: [
{
locale: "de",
localization_tags: [ ],
last_edit: "2014-04-14T08:43:37",
url: "/de/docs/Tools/Scratchpad",
title: "JavaScript-Umgebung"