Skip to content

Instantly share code, notes, and snippets.

View valarpirai's full-sized avatar

Valar valarpirai

View GitHub Profile
@valarpirai
valarpirai / rack_app.rb
Created August 1, 2022 12:16
Simple Rack server
require 'rack'
handler = Rack::Handler::WEBrick
class RackApp
def call(env)
req = Rack::Request.new(env)
if req.ip == "5.5.5.5"
[403, {}, ""]
else
@valarpirai
valarpirai / hash_lookup.rb
Created April 19, 2022 16:38
Ruby Hash lookup extension
module HashExtensions
def lookup(*keys)
keys.reduce(self) do |hash, key|
next_hash = hash[key] if hash.is_a?(Hash)
return nil if next_hash.nil?
next_hash
end
end
end
@valarpirai
valarpirai / app_config.rb
Last active January 31, 2022 11:48
Load configs from ERB based YML files in Rails application
module AppConfig
def self._config
@_config ||= ErbYaml.load_file("#{Rails.root}/config/app_configuration.yml")
end
def self.env
_config["env_name"]
end
end
(function( func ) {
jQuery.fn.addClass = function() { // replace the existing function on $.fn
func.apply( this, arguments ); // invoke the original function
this.trigger('classChanged'); // trigger the custom event
return this; // retain jQuery chainability
}
})(jQuery.fn.addClass);
jQuery(document).on('classChanged', '#ticket_original_request', function(){
@valarpirai
valarpirai / resp3.md
Created October 31, 2019 09:54 — forked from antirez/resp3.md
RESP3 protocol draft

RESP3 specification

Versions history:

  • 1.0, 2 May 2018, Initial draft to get community feedbacks.

Background

The Redis protocol has served us well in the past years, showing that, if carefully designed, a simple human readable protocol is not the bottleneck in the client server communication, and that the simplicity of the design is a major advantage in creating a healthy client libraries ecosystem.

Yet the Redis experience has shown that after about six years from its introduction (when it replaced the initial Redis protocol), the current RESP protocol could be improved, especially in order to make client implementations simpler and to support new features.

@valarpirai
valarpirai / dnsmasq OS X.md
Created October 31, 2019 05:54 — forked from ogrrd/dnsmasq OS X.md
Setup dnsmasq on OS X

Never touch your local /etc/hosts file in OS X again

NOTE this has been done properly by a guy here: https://www.stevenrombauts.be/2018/01/use-dnsmasq-instead-of-etc-hosts/

You should go and do that now, ignore all of this.

To setup your computer to work with *.dev domains, e.g. project.dev, awesome.dev and so on, without having to add to your hosts file each time.

Requirements

@valarpirai
valarpirai / node_nginx_ssl.md
Created September 28, 2019 07:14 — forked from bradtraversy/node_nginx_ssl.md
Node app deploy with nginx & SSL

Node.js Deployment

Steps to deploy a Node.js app to DigitalOcean using PM2, NGINX as a reverse proxy and an SSL from LetsEncrypt

1. Sign up for Digital Ocean

If you use the referal link below, you get $10 free (1 or 2 months) https://m.do.co/c/5424d440c63a

2. Create a droplet and log in via ssh

I will be using the root user, but would suggest creating a new user

@valarpirai
valarpirai / git.migrate.sh
Created April 9, 2019 13:07
Migrate git from origin to new origin repo
# Rename origin to old-origin
git remote rename origin old-origin
# Add new origin url
git remote add origin <new-remote>
# Fetch all branches and tags from old-origin
git fetch old-origin --prune
# Push all branches and tags from old-origin to new origin
@valarpirai
valarpirai / request_retry.py
Created March 1, 2019 13:20
Python script to send request and retry if failed
#!/bin/env python
import json
import requests
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
import time
# Returns a requests session with retry options
@valarpirai
valarpirai / git-pull.sh
Created December 17, 2018 05:53
Iterate over the git repositories in current directory and do git pull
find . -maxdepth 1 -type d \( ! -name . \) -exec bash -c "pull()
{
echo '--------- $(pwd)'
if [ -d \".git\" ]; then
echo '######### Start git pull'
git pull
else
echo '********* Not a git Repo **********'
fi
}