Skip to content

Instantly share code, notes, and snippets.

View pocheptsov's full-sized avatar

slava pocheptsov pocheptsov

View GitHub Profile
@pocheptsov
pocheptsov / renamer.cs
Created October 8, 2015 14:14
Rename files in current folder based on modification date
using System;
using System.IO;
namespace rename
{
class Program
{
static void Main(string[] args)
{
var subfolderName = args?.Length > 0 ? args[0] : Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
@pocheptsov
pocheptsov / gulp-flatten-es5.js
Created April 26, 2016 21:29
flatten gulp structure
import path from 'path'
const flatten = function(destFolder) {
return function(file) {
file.path = file.base + path.basename(file.path)
return destFolder
}
}
//usage
@pocheptsov
pocheptsov / dev-utils.sh
Last active November 3, 2016 21:01
Different DevOps commands
# find apache config file location
apache2 -V | grep 'HTTPD_ROOT\|SERVER_CONFIG_FILE'
# list top level global npm packages
npm -g ls --depth=0
# remove long path folder
rmdir node_modules /s /q
# windows: switch cmdline to run as Admin
#!/bin/bash
terraform_upgrade() {
OS_NAME="darwin"
if [[ "$OSTYPE" == "linux"* ]]; then
OS_NAME="linux"
fi
TEMP_PATH="/tmp"
@pocheptsov
pocheptsov / migrate_terraform_state_into_module.sh
Created July 9, 2018 17:40
Migrate multiple terraform resources under module structure
# grab all resources that will be marked for deletion and has [prefix]_[name].[suffix] template
# change module.name with yours naming
terraform plan -no-color awk '$1 == "-" && $2 ~ /.*_.*\..*/ { print "terraform state mv " $2 " module.name." $2 }' > mv_state.sh
# apply state changes
./mv_state.sh
# remove backups after checking state
rm -f terraform.tfstate.*
@pocheptsov
pocheptsov / merging_git_repositories_into_another_repository_subfolder.sh
Created August 30, 2018 21:44
Merging Git Repositories Into Another Repository Subfolder
git remote add -f js-tests git@github.com:cambridgebrainsciences/js-tests.git
git merge --no-commit -s ours js-tests/master
git read-tree --prefix=frontend/tests -u js-tests/master
git commit -m "Subtree merged in frontend/tests"
git remote remove js-tests
@pocheptsov
pocheptsov / rebase-feature-branch-on-squashed-commit.sh
Last active September 27, 2018 00:35
Rebase feature branch on top of squashed feature-base branch commit
# optionally set editor to the modern https://github.com/zyedidia/micro editor
git config --global core.editor micro
# find next commit after common commit of the long running side branches
COMMON_COMMIT="$(git merge-base long-running-feature-branch feature-branch-development)"
# get next to common commit
git log --pretty=format:"%h" "$COMMON_COMMIT...feature-branch-development" | tail -n1
> 50b1ed6
@pocheptsov
pocheptsov / loadStateReducer.ts
Created February 7, 2019 22:29
Initial redux-orm state loading
import orm from 'schema/orm'
export function loadStateReducer(state = orm.getEmptyState(), payload) {
// Create a Redux-ORM session from our entities "tables"
const session = orm.session(state)
const parseEntity = (modelName, stateSlotName) => {
const ModelClass = session[modelName]
const modelStates = payload.entities[stateSlotName]
@pocheptsov
pocheptsov / get-unused-routes.rb
Created November 7, 2019 20:02
Get Rails App unused routes
# https://hackernoon.com/get-unused-routes-of-large-rails-app-0h1cu32lj
Rails.application.eager_load!
unused_routes = {}
# Iterating over all non-empty routes from RouteSet
Rails.application.routes.routes.map(&:requirements).reject(&:empty?).each do |route|
name = route[:controller].camelcase
next if name.start_with?("Rails")
@pocheptsov
pocheptsov / client\.env.development
Created January 24, 2020 20:21
Dockerized Create React App and Proxied Backend
HOST=0.0.0.0
PROXY=http://localhost:3001