Skip to content

Instantly share code, notes, and snippets.

View Ciantic's full-sized avatar

Jari Pennanen Ciantic

View GitHub Profile
@Ciantic
Ciantic / register-innounpacker.reg
Created June 10, 2016 11:46
Register Innounpacker to Windows shell .exe files
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\exefile\shell\Innounp Extract\command]
@="C:\\\\Copies\\\\innounp\\\\innounp.exe -dInnoExtract -x \"%1\""
@Ciantic
Ciantic / bookmarklet.js
Created June 10, 2016 18:26
Bookmarklet to set Areena Yle Live to fullscreen
javascript: var v = document.getElementsByTagName("object")[0]; document.getElementsByTagName("html")[0].innerHTML = v.parentElement.innerHTML; var o = document.getElementsByTagName("object")[0]; o.style.position = "fixed"; o.style.top = "0"; o.style.bottom = "0"; o.style.left = "0"; o.style.right = "0";
@Ciantic
Ciantic / bookmarklet-youtube-fullscreen.js
Created June 10, 2016 18:27
Bookmarklet to show YouTube in fullscreen
javascript: var v = document.getElementsByTagName("video"); var u = window.location.href; var t = v && v[0] && (v[0].currentTime | 0); var m = /v=(.+?)(&|$)/.exec(u); if (m && m[1]) { var r = document.getElementsByTagName("html")[0]; r.innerHTML = '<iframe width="854" height="480" src="https://www.youtube.com/embed/' + m[1] + '?autoplay=1&start=' + t + '" frameborder="0" allowfullscreen style="width: 100% !important; height: 100% !important; left: 0px !important; position: fixed !important; top: 0px !important; z-index: 9999;"></iframe>'; setTimeout(function () { u = u.replace(/&t=\d+/, ""); v = document.getElementsByTagName("iframe")[0].contentDocument.getElementsByTagName("video")[0]; setInterval(function () { history.replaceState(null, null, u + "&t=" + Math.floor(v && v.currentTime)); }, 5000); }, 10000); }
// Hit Ctrl+T start typing "globalStyles", not found, start typing "Something", it is found
@Ciantic
Ciantic / typesafeapi-thinking.ts
Created July 12, 2016 10:54
typesafe api - thinking
abstract class ApiPromise<T> extends Promise<T> {
abstract onError(errorCode: string, cb: (data?: Object) => void);
abstract onError(errorCode: "VALIDATION_ERROR", cb: (data?: {
fields?: {
[fieldName: string] : string[]
},
messages?: string[]
}) => void);
}
@Ciantic
Ciantic / simpleEventListener.ts
Last active March 8, 2023 15:39
Very simple type-safe addListener, removeListener, trigger - basically Event / EventEmitter implementation with typesafety
export function simpleMapEvent<TParam, TRes = void, TContext = unknown>(context?: TContext) {
type T = { (this: TContext, inputs: TParam): TRes };
return {
cbs: [] as [T, T][], // First value is used for equality check, second is the bound version
addListener(cb: T, bindThis?: unknown) {
return this.cbs.push([cb, bindThis ? cb.bind(bindThis as TContext) : cb]);
},
removeListener(cb: T) {
const i = this.cbs.findIndex(([v, _]) => v == cb);
if (i >= 0) return this.cbs.splice(i, 1);
@Ciantic
Ciantic / crap.d.ts
Created September 20, 2016 17:24
impossible to default import
// Emulating this https://github.com/facebook/react/blob/df033180f0b56443985ad6e79c2eafdcc49384f7/src/addons/transitions/ReactTransitionGroup.js
// Note that some-crap module does not have export named "default"
declare module "some-crap" {
class Thingie {
}
export = Thingie;
}
@Ciantic
Ciantic / asynctest.js
Created September 21, 2016 08:23
Fat arrow async bug
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator.throw(value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments)).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t;
/// <reference path="C:/Users/jarppa2/.typings/node/index.d.ts" />
/// I wish there a way to reference Node without polluting application's type definitions
let fs = require("fs");
let nodeModulesLink = (projectDirectory) => {
let linkLocation = `node_modules/${projectDirectory}`;
let linkTarget = `../${projectDirectory}`;
fs.symlink(linkTarget, linkLocation, "junction", () => {
if (!fs.existsSync(linkLocation)) {
console.error(`Unable to create symbolic link (or junction) for "${linkLocation}" -> "${linkTarget}"`);
@Ciantic
Ciantic / package.json
Created December 10, 2016 17:15
Cloneable problem tsc
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"@blueprintjs/core": "^1.3.1"
},
"devDependencies": {},
"scripts": {