Skip to content

Instantly share code, notes, and snippets.

@madox2
madox2 / kdice-autoendturn.js
Created Apr 25, 2020
Enables auto-end turn for KDice
View kdice-autoendturn.js
// ==UserScript==
// @name KDice Auto-end turn
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Auto-end turn for KDice
// @author You
// @match https://kdice.com/*
// @grant none
// ==/UserScript==
@madox2
madox2 / serve-prod-build.js
Last active Apr 14, 2019
node js server that serves static folder and makes proxy to api server
View serve-prod-build.js
var proxy = require('express-http-proxy')
var express = require('express')
var app = express()
// e.g. I want to serve app from local dir on localhost:8000/app
// and use API from remote server http://myserver/api
const localAppStaticDir = '../somedir/someapp/build'
const localAppPath = '/app'
const localApiPath = '/api'
@madox2
madox2 / jsconfig.json
Created Nov 17, 2018
Default config for js projects
View jsconfig.json
{
"compilerOptions": {
"checkJs": false,
"allowJs": true,
"noEmitOnError": true,
"noEmit": true,
"target": "es6",
"module": "commonjs",
"jsx": "react"
},
@madox2
madox2 / snippets.js
Created Aug 8, 2017
Snippets to prettify
View snippets.js
const a = {b: 1, c: 2}
cost Component = () => (
<div prop={1}
other={2} />
)
import { hahahahahahaha, heheheheheheh, huhuhuhuhuhu, hihihihihihi, hohohohoho } from 'react-hahahaha-heheheh-huhuhu'
function foo(
View git_lg_alias
git config --global alias.lg "log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(bold yellow)%d%C(reset)' --all"
@madox2
madox2 / vim_eslint_fix.vim
Created Oct 12, 2016
Function which runs eslint --fix and saves the buffer. It is mapped to :W command
View vim_eslint_fix.vim
function ESLintFix()
write
silent execute "!./node_modules/.bin/eslint --fix %"
edit! %
redraw!
endfunction
command W call ESLintFix()
View themeable_shining_example.js
import React, { Component } from 'react'
import { theme, Text, View, withStyles } from 'react-native-themeable'
const redTheme = withStyles([
{
$type: Text,
color: 'white',
fontSize: 26,
}, {
$type: View,
@madox2
madox2 / windows-1250_to_utf-8.py
Created Aug 26, 2016
Could be useful when encoding subtitles
View windows-1250_to_utf-8.py
#!/usr/bin/python
import sys
import urllib
source_enc = 'windows-1250'
target_enc = 'utf-8'
print '============================================='
print '=== conversion from windows-1250 to utf-8 ==='
print '============================================='
@madox2
madox2 / intercept_module.js
Last active Aug 10, 2016
intercepting module in node
View intercept_module.js
const M = require('module')
const _load = M._load;
M._load = function(request, ...rest) {
const _module = _load(request, ...rest)
if (request === './module1.js') {
return function(...args) {
console.log(`intercepting ${request}`)
_module(...args)
}
@madox2
madox2 / asynchronous_tasks_sequentially.js
Created Aug 7, 2016
run asynchronous tasks sequentially
View asynchronous_tasks_sequentially.js
/**
* Returns promise which runs given callback functions in series and
* collect results in array.
*
* @param {array} promises - array of callback functions
*/
function promiseAllSeq(promises) {
var data = [];
return promises.reduce((p, fn) => p.then(fn).then(i => (data.push(i), data)), Promise.resolve());