Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀
💻 🌍

Unathi Chonco choncou

🚀
💻 🌍
View GitHub Profile
@choncou
choncou / rails_optimistic_locking_example.rb
Last active Jun 15, 2021
Optimistic Locking in Rails: Preventing outdated updates
View rails_optimistic_locking_example.rb
# Run with `ruby rails_optimistic_locking_example.rb`
#
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
@choncou
choncou / verify_jwt.rb
Last active Mar 23, 2021
Verify JWTs with JWKS
View verify_jwt.rb
module Auth
module VerifyJwt
extend self
JWKS_CACHE_KEY = "auth/jwks-json".freeze
JWKS_URL = "https://#{Rails.configuration.auth0[:auth_domain]}/.well-known/jwks.json".freeze
def call(token)
JWT.decode(
token,
@choncou
choncou / hashify_from_dot_notation.rb
Created Jul 8, 2019
Hash from dot-notation keys
View hashify_from_dot_notation.rb
def hash_from_dot_notation(value)
return value unless value.is_a?(Hash)
value.deep_stringify_keys.each_with_object({}) do |(k,v), result|
root, child = k.split('.')
if child
result[root] ||= {}
View linkable.js
$(document).on('turbolinks:load', () => {
linkableElements = $('.js-linkable');
linkableElements.click((e) => {
e.preventDefault();
const { delegateTarget } = e;
const href = $(delegateTarget).data('href');
Turbolinks.visit(href);
});
@choncou
choncou / linkable.html
Created Feb 17, 2019
Code Snippet for "5 Opinionated Tips for Creating a Maintainable Rails Application"
View linkable.html
<div class="js-linkable" data-href="https://example.com">
<!--
Contents of this div
-->
</div>
@choncou
choncou / CoreDataStack.swift
Last active May 22, 2016
Useful CoreData Boilerplate
View CoreDataStack.swift
//
// CoreDataStack.swift
//
//
// Created by Fernando Rodríguez Romero on 21/02/16.
// Copyright © 2016 udacity.com. All rights reserved.
//
import CoreData
@choncou
choncou / recursion.py
Last active Mar 4, 2016 — forked from neptunius/recursion.py
Comparison of iterative and recursive functions
View recursion.py
import unittest
def factorial(n):
'''factorial(n) returns the product of the integers 1 through n for n >= 0,
otherwise raises ValueError for n < 0 or non-integer n'''
# implement factorial_iterative and factorial_recursive below, then
# change this to call your implementation to verify it passes all tests
...
return factorial_iterative(n)
@choncou
choncou / LinkedList.py
Last active Feb 9, 2016
Implementation of Linked List data structure with broad set of functions
View LinkedList.py
class LinkedList:
def __init__(self, value=None):
self.head = None
if value is not None:
self.head = self.Node(value)
self.tail = self.head
self.count = 0
if value is not None:
self.countUp()