Skip to content

Instantly share code, notes, and snippets.

@starstuck
starstuck / debug-proxy.js
Last active December 30, 2015 12:19
Proxy setup for developing and debugging web applications. It creates node.js servercombining express + http-proxy to provide uncompressed JS and CSS over proxied live content. It works very well with source maps.
/**
* Web application debug proxy server.
*
* It is suited for hosting uncompressed sources of front-end assets and proxy dynamic
* requests to servers preparing data. I find similar setup also useful for investigating
* issues on production servers by going through the proxy, which use local unminified
* JS and CSS on top of production html pages.
*
* To run following example you will need to have http-proxy, express and send packages installed.
*
@starstuck
starstuck / git-svn-fix-tags.sh
Last active January 2, 2016 09:18
Convert all git-svn pseudo tag branches to proper tags.
#!/usr/bin/env bash
#
# Following script will work with tags preficed with svn, having mapping like:
# tags = project/tags/*:refs/remotes/svn/tags/*
# If you use differnet paths mapping, you may need to adjust it a bit.
#
git for-each-ref --shell --format='parent=%(parent) refname=%(refname)' refs/remotes/svn/tags/ | \
while read entry
do
@starstuck
starstuck / raspberrypi-dht11.py
Created October 30, 2015 12:14
Read humidity and temperature from DHT11 sensor connected to RaspbberyPi
#!/usr/bin/env python
# -*- coding: utf8 -*-
#
# Read humidity and temperature from DHT11 sensor connected to RaspberryPi.
#
# DHT11 protocol depends on exact timing. Sometimes linux kernel may evict your
# process, or GC can cause program to miss some of a bits from transmission. In
# that case following application will raise an error and you can try to run it
# again
#
@starstuck
starstuck / async_reservations.js
Created October 4, 2018 14:59
Monitor aync resources in node.js application
import asyncHooks from 'async_hooks';
const reservations = new Map();
asyncHooks.createHook({
init: function init(asyncId, type, triggerAsyncId) {
const e = {};
Error.captureStackTrace(e, init);
reservations.set(asyncId, {type, triggerAsyncId, stack: e.stack});
},
destroy: function destroy(asyncId) {
@starstuck
starstuck / install-slack-black.sh
Last active January 24, 2019 09:32
Install Slack black theme on macOS
#!/usr/bin/env bash
sudo mkdir -p /Library/Application\ Support/Slack/Resources
curl https://raw.githubusercontent.com/laCour/slack-night-mode/master/css/raw/black.css | sudo tee /Library/Application\ Support/Slack/Resources/black.css > /dev/null
sudo patch --backup /Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js << EOF
*** ssb-interop.js
--- ssb-interop.js.patched
***************
*** 95,99 ****
const mainModule = require.resolve('../ssb/main.ts');
const isDevMode = loadSettings.devMode && isPrebuilt();
@starstuck
starstuck / restic.sh
Last active April 1, 2019 10:42
Restic multi-arch wrapper
#!/usr/bin/env bash
# -*- sh -*-
#
# This script runs right restic executable for system where it is called.
# Download restic releases to ../libexec folder and update VERSION valriable.
# It will also set RESTIC_REPOSITORY, based on assumption that the script lies
# in bin folder in the repository.
VERSION="0.9.3"
SYS=$(uname -s | tr '[:upper:]' '[:lower:]')
@starstuck
starstuck / keybase.md
Created March 8, 2019 13:26
Keybase proof

Keybase proof

I hereby claim:

  • I am tomstarstuck on github.
  • I am starstuck (https://keybase.io/starstuck) on keybase.
  • I have a public key ASCy3r8YyuneO7itqGqwcGXsNWL3LCZG-IG8rjADhGmYIgo

To claim this, I am signing this object:

@starstuck
starstuck / pom.xml
Last active April 3, 2019 14:39
Example of maven to download and invoke swagger codegen
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>my-project</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
@starstuck
starstuck / actions.ts
Last active April 18, 2019 17:24
Concise, strong typing in Redux actions and reducers (TypeScript).
import { ActionCreatorsMapObject, AnyAction } from 'redux';
export enum ActionType {
ReportError = 'REPORT_ERROR',
UpdateToDos = 'UPDATE_TODOS'
}
type ThunkDispatch = <T extends { type: ActionType }>(action: T) => T;
type ThunkAction<A extends { type: ActionType }, S, E> = (
@starstuck
starstuck / ssh-agent.sh
Created June 17, 2019 09:25
Script to load and share ssh-agent across all terminal session on single system. Add it to your ~/.profile.
# -*- sh -*-
export SSH_AGENT_FILE=~/.ssh/agent
start() {
(umask 077; ssh-agent >| ${SSH_AGENT_FILE})
. ${SSH_AGENT_FILE}
ssh-add
}
if [ ! -f "${SSH_AGENT_FILE}" ]; then