Skip to content

Instantly share code, notes, and snippets.

@gurunars
gurunars / rebase-feature-branch.sh
Created November 5, 2024 10:18
Rebase feature branch
FEATURE_BRANCH=fill-me
echo "Backup feature branch to server"
git checkout ${FEATURE_BRANCH}
git push origin ${FEATURE_BRANCH}
echo "Refresh main"
git checkout main
git pull origin main
@gurunars
gurunars / ws-preinstall.mjs
Created August 7, 2024 07:13
Produces a yarn.lock that should be commented but does it ONLY for dev dependencies.
/** Inspired by https://classic.yarnpkg.com/blog/2016/11/24/lockfiles-for-all/
*
* Produces a yarn.lock that should be commented but does it ONLY for dev dependencies.
*/
import fs from 'node:fs'
import { execSync, exec } from 'node:child_process'
const getOutput = (cmd) => execSync(cmd).toString()
@gurunars
gurunars / birthday_loops.py
Last active June 5, 2019 10:07
Loopy and non loopy solutions
import json
def find_meaning(param):
return 11
def try_luck(param):
return 7
@gurunars
gurunars / gist:f3645a9289fd642242a1ce29d133a4d4
Created January 14, 2018 18:55
Regexp to replace all javaish docstrings that could be one-liners with one line docstrings e.g. via IntelliJ
Regexp:
\/\*\*\n\s*\*(.{1,80})\n\s*\*\/
With:
/**$1 */
From:
/**
* Foobar
*/
@gurunars
gurunars / cleanup_docker.sh
Created April 20, 2017 13:41
cleanup-docker
#!/bin/bash
docker ps -aqf "status=exited" | xargs -r docker rm -f
docker images -qf "dangling=true" | xargs -r docker rmi -f
docker volume ls -qf "dangling=true" | xargs -r docker volume rm
ffmpeg -i input.mp4 -vf scale=360:640 -pix_fmt rgb24 output.gif
@gurunars
gurunars / base_test.py
Last active May 26, 2017 10:52
Python unit test with multipatching
from abc import ABCMeta, abstractproperty
import unittest
import mock
class BaseTest(unittest.TestCase):
__metaclass__ = ABCMeta
@gurunars
gurunars / sample-program
Last active July 12, 2016 11:59
Sample Linux service config for init.d
#!/bin/sh
# Put to /usr/bin/sample-program
sleep 600 &
PID="$!"
# Trap is required to kill all child processes when the service is stopped
trap "kill $PID" exit INT TERM KILL TERM
@gurunars
gurunars / path_finder.py
Last active October 16, 2016 19:14
Djikstra algorithm implementation in Python
"""
Glossary used in the functions below:
Node can be virtually any hashable datatype.
:param start: starting node
:param end: ending node
:param weighted_graph: {"node1": {"node2": "weight", ...}, ...}
"""
@gurunars
gurunars / find_latest_ami_name.py
Last active October 30, 2020 01:41
AWS lambda function to find the latest Amazon AMI
"""
Publish the function to S3:
cd $DIR_WITH_THIS_SCRIPT
zip find_latest_ami_name.zip find_latest_ami_name.py
aws s3 cp find_latest_ami_name.zip s3://$YOUR_S3_BUCKET/find_latest_ami_name.zip
"""
import json