Skip to content

Instantly share code, notes, and snippets.

View wakproductions's full-sized avatar
💭
Hey, I'm working on it!

Winston Kotzan wakproductions

💭
Hey, I'm working on it!
View GitHub Profile
@arkadiyt
arkadiyt / token.rb
Last active January 12, 2023 20:01
Generate signed tokens in ruby
require 'base64'
require 'json'
require 'openssl'
require 'time'
def secure_compare(a, b)
return false unless a.bytesize == b.bytesize
l = a.unpack "C#{a.bytesize}"
@jesster2k10
jesster2k10 / README.md
Last active July 28, 2024 15:33
JWT Auth + Refresh Tokens in Rails

JWT Auth + Refresh Tokens in Rails

This is just some code I recently used in my development application in order to add token-based authentication for my api-only rails app. The api-client was to be consumed by a mobile application, so I needed an authentication solution that would keep the user logged in indefinetly and the only way to do this was either using refresh tokens or sliding sessions.

I also needed a way to both blacklist and whitelist tokens based on a unique identifier (jti)

Before trying it out DIY, I considered using:

@davidteren
davidteren / Rails, Puma & Nginx.md
Last active July 8, 2024 16:15
Example setup for Puma with Nginx in a Rails app

In the apps config/puma.rb file:

Change to match your CPU core count
# Check using this on the server => grep -c processor /proc/cpuinfo
workers 4

# Min and Max threads per worker
threads 1, 6

app_dir = File.expand_path('../..', FILE)

@cecilemuller
cecilemuller / 2019-https-localhost.md
Last active July 20, 2024 14:39
How to create an HTTPS certificate for localhost domains

How to create an HTTPS certificate for localhost domains

This focuses on generating the certificates for loading local virtual hosts hosted on your computer, for development only.

Do not use self-signed certificates in production ! For online certificates, use Let's Encrypt instead (tutorial).

@drbrain
drbrain / run
Created November 2, 2017 22:46
Don't convert hash keys, it's slower than using the "natural" key of the input data
$ ruby -v t.rb
ruby 2.4.2p198 (2017-09-14 revision 59899) [x86_64-darwin17]
Lookup
Warming up --------------------------------------
Symbol Hash, Symbol Key
259.197k i/100ms
String Hash, String Key
231.953k i/100ms
Symbol Hash, String Key
203.959k i/100ms
@dvdasari
dvdasari / gist:439ce7c1814c2392c3bf
Last active March 23, 2020 12:05
docker commands
1. Create new container
a) docker run -i -t ubuntu /bin/bash
b) docker run --name rails_dev_container -i -t ubuntu ubuntu /bin/bash
The command line flags - i -t provide an interactive shell in the new container
2. Show running docker containers ==> docker ps
3. Show list of current containers ==>
a) docker ps -a (Show all containers, both stopped and running)
b) docker ps -n x (shows the last x containers, running or stopped, ex: docker ps -n 5)
@darryn
darryn / custom line item metafields
Created December 1, 2014 03:11
Shopify - custom line items with metafields
{% if product.metafields.properties.size > 0 %}
<div class="col-xs-12 col-lg-6">
{% for l_item in product.metafields.properties %}
{% assign key = l_item.first | split: ':' %}
{% assign key_type = key.last %}
{% assign key_title = key.first %}
{% assign value = l_item.last %}
<div class="form-group">
<label>{{ key_title }}</label>
{% if key_type == 'select' %}
@ngsmrk
ngsmrk / sidekiq_monitoring
Created August 11, 2014 11:51
Sidekiq queue checking via rails console
stats = Sidekiq::Stats.new
stats.queues
stats.enqueued
stats.processed
stats.failed
@swithrow
swithrow / instance-name-tag.sh
Last active August 18, 2023 15:16
EC2 Instance Name Tag in the bash prompt.
#!/bin/bash
#
# copy this into /etc/profile.d/instance-name-tag.sh
#
# you will need:
# - curl, jq, and aws cli installed
# - an IAM role that gives the EC2 instance access to describe tags
#
@darryn
darryn / Shopify tag filter groups
Last active August 23, 2023 03:51
Create tag filter groups in Shopify. This snippet is designed to group and separate out collection tags. It requires the tags to share a common value prepended to the tag with an underscore. E.g. to create a separate tag filter group for 'brands', each product will need to be tagged with 'brand_Nike' or 'brand_Reebok'. Some of this is probably l…
{% if template contains 'collection' and collection.all_tags.size > 1 %}
<!-- A recursive loop to catch and filter out the different tag categories -->
{% assign c = 0 %}
{% for t in collection.all_tags %}
{% capture cat %}{{ cat }}{% capture temp_cat %}{% if t contains '_' %}{% assign cat_grp = t | split: '_' %}{{ cat_grp.first }}{% endif %}{% endcapture %}{% unless cat contains temp_cat %}{% if t contains '_' %}{% assign new_cat_grp = t | split: '_' %}{{ new_cat_grp.first }}{% endif %}{% unless forloop.last %}+{% endunless %}{% assign c = c | plus: 1 %}{% endunless %}{% endcapture %}
{% endfor %}
<!-- create array of tag categories -->
{% assign cat_array = cat | split: '+' %}