Skip to content

Instantly share code, notes, and snippets.

View choncou's full-sized avatar
🚀
💻 🌍

Unathi Chonco choncou

🚀
💻 🌍
View GitHub Profile
@choncou
choncou / LinkedList.py
Last active February 9, 2016 20:03
Implementation of Linked List data structure with broad set of functions
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()
@choncou
choncou / recursion.py
Last active March 4, 2016 07:35 — forked from neptunius/recursion.py
Comparison of iterative and recursive functions
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 / CoreDataStack.swift
Last active May 22, 2016 21:15
Useful CoreData Boilerplate
//
// CoreDataStack.swift
//
//
// Created by Fernando Rodríguez Romero on 21/02/16.
// Copyright © 2016 udacity.com. All rights reserved.
//
import CoreData
@choncou
choncou / linkable.html
Created February 17, 2019 19:26
Code Snippet for "5 Opinionated Tips for Creating a Maintainable Rails Application"
<div class="js-linkable" data-href="https://example.com">
<!--
Contents of this div
-->
</div>
$(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 / hashify_from_dot_notation.rb
Created July 8, 2019 16:13
Hash from dot-notation keys
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] ||= {}
@choncou
choncou / verify_jwt.rb
Last active March 23, 2021 18:56
Verify JWTs with JWKS
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 / rails_optimistic_locking_example.rb
Last active June 15, 2021 12:10
Optimistic Locking in Rails: Preventing outdated updates
# 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" }