Skip to content

Instantly share code, notes, and snippets.

Alex Grin lyoshenka

Block or report user

Report or block lyoshenka

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lyoshenka
lyoshenka / s3dir.html
Last active Oct 2, 2019
Upload this file to an s3 bucket with static website hosting enabled to get a directory listing of the bucket contents. Example: http://build.lbry.io
View s3dir.html
<!DOCTYPE html>
<html>
<head>
<title>Files</title>
</head>
<body>
<div id="navigation"></div>
<div id="listing"></div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
@lyoshenka
lyoshenka / 45-75.bookmarklet.js
Created Jan 25, 2019
Highlight the 45th through 75th character of a piece of text
View 45-75.bookmarklet.js
javascript:!function(){var a=document.createElement("style");a.type="text/css";a.innerHTML="p:hover, li:hover, dt:hover, dd:hover, h1:hover, h2:hover, h3:hover, h4:hover, h5:hover, h6:hover { outline: 2px solid red; }";document.body.appendChild(a);var d=function(c){var b=c.target.innerText;c.target.innerHTML=b.substring(0,45)+"<span style='color: red;'>"+b.substring(45,75)+"</span>"+b.substring(75);document.removeEventListener("click",d);a.parentNode.removeChild(a)};document.addEventListener("click",d)}();
@lyoshenka
lyoshenka / clean-search-engines.js
Created Oct 30, 2018
Delete all non-custom search engines from chrome
View clean-search-engines.js
// DANGER: this will delete all search engines that don't have a `.` in their keyword
// Go to chrome://settings/searchEngines and put this in the console
settings.SearchEnginesBrowserProxyImpl.prototype.getSearchEnginesList()
.then(function(val) {
val.others.sort(function(a, b) { return b.modelIndex - a.modelIndex; });
val.others.forEach(function(engine) {
if (engine.keyword.includes(".")) {
settings.SearchEnginesBrowserProxyImpl.prototype.removeSearchEngine(engine.modelIndex);
}
@lyoshenka
lyoshenka / maintenance.html
Last active Oct 17, 2017 — forked from pitch-gist/gist:2999707
Simple Maintenance Page
View maintenance.html
<!doctype html>
<html><head>
<meta charset="utf-8" />
<title>Site Maintenance</title>
<style type="text/css">
body { padding: 50px 30px 30px; font: 20px Helvetica, sans-serif; color: #222; line-height: 1.4 }
h1 { font-size: 40px; }
article { text-align: left; max-width: 650px; margin: 0 auto; }
a { color: #dc8100; padding: 3px }
a:hover { color: #fff; background-color: #dc8100 }
@lyoshenka
lyoshenka / tx.go
Created Sep 4, 2017
A simple, neat way to wrap code in an sql transaction with proper committing/rollbacking and error handling.
View tx.go
// TxFunc is a function that can be wrapped in a transaction
type TxFunc func(tx *sql.Tx) error
// WithTx wraps a function in an sql transaction. After the function returns, the transaction is
// committed if there's no error, or rolled back if there is one.
func WithTx(db *sql.DB, f TxFunc) (err error) {
tx, err := db.Begin()
if err != nil {
return err
}
@lyoshenka
lyoshenka / asciiart.html
Last active Aug 13, 2017
Convert image to ASCII animation. This may not work through rawgit.com because of CORS, so check it out locally. Source: http://thecodeplayer.com/walkthrough/cool-ascii-animation-using-an-image-sprite-canvas-and-javascript
View asciiart.html
<html>
<head>
<style>
* {margin: 0; padding: 0;}
body { text-align: center; }
#ascii { font-family: monospace; font-size: 11px; line-height: 70%; }
#sprite { display: none; }
#container { overflow: hidden; display: inline-block; }
</style>
</head>
View lbry_install_from_source.sh
#!/usr/bin/env bash
set -euo pipefail
#set -x
if [ "$(uname)" == "Darwin" ]; then
echo "macOS install coming soon"
exit 1
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
echo "Starting linux install"
@lyoshenka
lyoshenka / coding_maxims.md
Last active Nov 9, 2019
Keep this in mind
View coding_maxims.md

Coding Maxims

  • code is debt (and bad code is an unhedged call option)
    • cant have 0-days or bugs if I dont write any code
    • our users dont care about the code
    • every line of code has costs (your time, readability, maintainability, complexity)
      • its like owning a house with lots of rooms. its nice when your friends come over once a month, but you pay rent every day
    • dont add features unless you're sure it is necessary
    • dont optimize prematurely
@lyoshenka
lyoshenka / api_doc.py
Created Dec 9, 2016
Minimalistic API documentation for Python
View api_doc.py
# -*- coding: utf-8 -*-
from __future__ import print_function
"""Minimal API documentation generation."""
#------------------------------------------------------------------------------
# Imports
#------------------------------------------------------------------------------
import inspect
@lyoshenka
lyoshenka / RedisLock.class.php
Last active Nov 6, 2016
Atomic, distributed locking with PHP and Redis
View RedisLock.class.php
<?php
class RedisLockFailException extends Exception {}
class RedisLock
{
const DEFAULT_TIMEOUT = 20;
// what to do if we cannot get lock
const FAIL_EXCEPT = 'fail_except'; // throw exception
You can’t perform that action at this time.