Skip to content

Instantly share code, notes, and snippets.

@jadechip
jadechip / typography
Created January 26, 2014 00:41
A typography configuration
// http://modularscale.com/scale/?px1=16&px2=12&ra1=1.618&ra2=0
// == || MODULAR SCALE || ==
$base-text-size: 1em
$important-number: 0.75em
$omicron: golden-ratio($base-text-size, 5) // 177.425
$xi: golden-ratio($important-number, 5) // 133.066
@jadechip
jadechip / APIHandler.h
Created May 13, 2015 14:05
Objective-C classes for retrieving a user authentication token and storing it in the keychain using AFNetworking and SSKeychain
//
// APIHandler.h
// Orakuru
//
// Created by Mitrmitri on 11/19/2557 BE.
// Copyright (c) 2557 Codemy. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <AFNetworking/AFNetworking.h>
@jadechip
jadechip / singularDimension.js
Last active February 20, 2017 20:56
Converts a multi-dimensional, intergalactic space array into the much more tame singular dimension - Made for CitrusByte ☄
var pancake = function pancake(inputArray) {
return inputArray.reduce(function (accumulation, value) {
if(Array.isArray(value)) {
return accumulation.concat(pancake(value));
} else {
return accumulation.concat(value);
}
}, []);
@jadechip
jadechip / binary-gap.py
Last active September 6, 2019 13:10
Programming challenge: Binary Gap
def solution(N):
max_value = 2147483647
min_value = 1
if (N < min_value or N > max_value):
return 0
binary = bin(N)
return find_gaps(list(binary))
def find_gaps(binary_list, gaps=[]):
first_index = 0
@jadechip
jadechip / odd-occurrences.py
Created September 4, 2019 14:58
Programming challenges: Odd Occurrences In Array
def solution(A):
result = 0
for num in A:
result ^= num
return result
@jadechip
jadechip / two-number-sum.py
Last active September 5, 2019 09:34
Programming challenges: Two Number Sum
# Naive approach - O(n)
def twoNumberSum(array, targetSum):
for num in array:
if num == 0:
return sorted([num, targetSum])
if (num < targetSum):
diff = targetSum - num
if diff in array:
if array.index(diff) != array.index(num):
result = [num, diff]
@jadechip
jadechip / nth-fibonacci.py
Last active September 5, 2019 15:27
Programming challenges: Nth Fibonacci
# O(n) time | O(n) space
def getNthFib(n):
memo = {1: 0, 2: 1} # start of with initial values in cache
if n in memo:
return memo[n]
else:
memo[n] = calcFib(n) # store result in cache
return memo[n]
# O(n) time | O(1) space
@jadechip
jadechip / binary-search.py
Last active September 6, 2019 12:58
Programming challenges: Binary Search
def binarySearch(array, target):
# Array has to be sorted in order to check surrounding elements
left = 0
right = len(array) - 1
while left <= right:
mid = (left + right)
guess = array[mid]
if guess == target:
return mid
if guess > target:
@jadechip
jadechip / is-palindrome.py
Last active September 6, 2019 13:23
Programming challanges: Is Palindrome
# O(n)
def isPalindrome(string):
left = 0
right = len(string) - 1
while left < right:
if string[left] == string[right]:
left += 1
@jadechip
jadechip / ceasar-cipher-encryptor.py
Created September 12, 2019 21:10
Programming challenges: Ceasar Cipher Encryptior
def caesarCipherEncryptor(string, key):
alphabet = list("abcdefghijklmnopqrstuvwxyz")
tmp = ""
for char in string:
idx = (alphabet.index(char) + key) % len(alphabet)
tmp += alphabet[idx]