Skip to content

Instantly share code, notes, and snippets.

View coderxin's full-sized avatar
🦀

Andrejs Eisaks coderxin

🦀
  • Zürich, Switzerland
  • 02:24 (UTC +02:00)
  • X @coderxin
View GitHub Profile
@coderxin
coderxin / git-split
Created December 22, 2023 13:34
git-split: Script to duplicate a file while preserving git line history
#!/bin/sh
# Script to duplicate a file while preserving git line history
#
# This could be useful if you want two copies of a file,
# say, one where you are doing a bunch of disruptive work,
# and another that remains largely unchanged. The project continues to use the old,
# stable version, but there’s a feature flag to switch to the new one.
# Eventually, you’ll make the new one the default version.
#
# Utility to clone all non-achived Git repos from Organisation
# - Clone only if target folder does not exist
gh repo list CHANGE_ORG_NAME --no-archived --limit 1000 | while read -r repo _; do
DIRECTORY=$(echo "$repo" | cut -d "/" -f 2)
if [ ! -d "$DIRECTORY" ]; then
echo "$DIRECTORY does not exist."
gh repo clone "$repo" "$DIRECTORY"
fi
done
@coderxin
coderxin / checksum.rb
Created December 6, 2022 14:30 — forked from andrewbroman/checksum.rb
Ruby: create checksum on hash
# Thanks to tenderlove on Peepcode play by play
require 'digest/md5'
def fetch username
records = JSON.parse get username
records.each do |hash|
checksum = Digest::MD5.hexdigest Marshal.dump(hash)
hash['checksum'] = checksum
end
@coderxin
coderxin / reinstall_mysql57.sh
Created November 29, 2022 16:14
How to reinstall broken MySQL (with brew)
brew services stop mysql@5.7
brew remove mysql@5.7
brew cleanup
rm -rf /opt/homebrew/Cellar/mysql@5.7
rm -rf /opt/homebrew/var/mysql
rm /opt/homebrew/etc/my.cnf.default
rm /opt/homebrew/etc/my.cnf
@coderxin
coderxin / no_cookies.rb
Created August 16, 2022 15:24 — forked from apeckham/no_cookies.rb
remove set-cookie headers if page is meant to be cached, bc fastly doesn't cache responses with set-cookie headers
class NoCookies
def initialize(app)
@app = app
end
def call(env)
@app.call(env).tap do |_, headers, _|
if headers['Cache-Control'] =~ /public/ || headers['Surrogate-Control']
headers.delete 'Set-Cookie'
end
@coderxin
coderxin / rspec_mock_net_http.rb
Created August 19, 2020 15:49 — forked from rahsheen/rspec_mock_net_http.rb
Easily Mock Net::HTTP with Rspec
require 'rails_helper'
RSpec.describe MyWorker, type: :job do
include ActiveJob::TestHelper
let(:sqs_msg) { double AWS::SQS::ReceivedMessage,
id: 'fc754df7-9cc2-4c41-96ca-5996a44b771e',
body: 'test',
delete: nil }
@coderxin
coderxin / axios-catch-error.js
Created September 16, 2019 08:36 — forked from fgilio/axios-catch-error.js
Catch request errors with Axios
/*
* Handling Errors using async/await
* Has to be used inside an async function
*/
try {
const response = await axios.get('https://your.site/api/v1/bla/ble/bli');
// Success 🎉
console.log(response);
} catch (error) {
// Error 😨
@coderxin
coderxin / redis-autostart-osx.md
Created July 2, 2018 20:00 — forked from subfuzion/redis-autostart-osx.md
redis auto start OS X

Install with Homebrew

brew install redis

Set up launchctl to auto start redis

$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents

/usr/local/opt/redis/ is a symlink to /usr/local/Cellar/redis/x.y.z (e.g., 2.8.7)

@coderxin
coderxin / README-Template.md
Created December 11, 2017 00:06 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@coderxin
coderxin / Gemfile
Last active May 31, 2018 12:34
Factories from FactoryGirl in rails console
gem 'factory_girl_instruments'