Skip to content

Instantly share code, notes, and snippets.

View Odame's full-sized avatar

Prince Odame Odame

View GitHub Profile
# 3 ways to give change for 4
# with denomination 1 and 2
# 1+1+1+1, 1+1+2, 2+2.
#
# 1+1+2 == 2+1+1
# count_change(4, [1,2]) # => 3
# count_change(10, [5,2,3]) # => 4
# count_change(11, [5,7]) # => 0
@Odame
Odame / AudioExtractor.java
Last active May 20, 2021 09:09 — forked from ArsalRaza/VideoUtils.java
Extract Audio from Video, Mute Video, Crop Video from start, Crop Video from end Android MediaMuxer - JAVA
import android.annotation.SuppressLint;
import android.media.MediaCodec;
import android.media.MediaExtractor;
import android.media.MediaFormat;
import android.media.MediaMetadataRetriever;
import android.media.MediaMuxer;
import android.util.Log;
import java.io.IOException;
import java.nio.ByteBuffer;
@Odame
Odame / access-mac-localhost-from-parallels-desktop-ie-edge.md
Last active February 25, 2019 19:30 — forked from ernsheong/access-mac-localhost-from-parallels-desktop-ie-edge.md
Accessing macOS localhost from Parallels Desktop IE or Edge

Access macOS localhost from IE or Edge within Parallels Desktop

This issue is so infuriating that I'm going to take some time to write about it.

  1. MOST IMPORTANT. Your local development server must be bound to IP address 0.0.0.0. Some do this by default, but many don't. You need to make sure that you run your local server with correct IP bindings. You may need to provide additional flags to your serve commands e.g. polymer serve --hostname domain.local, hugo serve --bind 0.0.0.0. If you use a named domain like domain.local, it has to be defined in /etc/hosts and pointing at 0.0.0.0.

  2. My Parallels setting is using Shared Network, nothing special there.

  3. Open macOS Terminal and type ifconfig. Look for the value under vnic0 > inet. It is typically 10.211.55.2.

@Odame
Odame / db_service.py
Last active October 23, 2018 05:34
Service for accessing a MySQL database in a Flask application, where all db calls in a single request must use a single db connection
# coding: utf-8
"""
Service for accessing a MySQL database in a flask application, where all db calls in a single request must use a single db connection.
Uses the Borg pattern, with state stored in a thread local (g), in NOT order to leak state across multiple threads
"""
import logging as log
import MySQLdb as mDb
from functools import wraps
from flask import g
@Odame
Odame / ranking.js
Created August 5, 2018 23:09
Solution to test question in form.
/**
* Sort an array of objects based on ranking
* @param {{name: String, ranking: Number}[]} objectArray
*/
const sortByRanking = (objectArray) => {
return objectArray.sort((obj1, obj2) => obj1.ranking-obj2.ranking);
};
/**
@Odame
Odame / mysqldb_query_generator.py
Created June 22, 2017 09:18 — forked from robcowie/mysqldb_query_generator.py
Memory-efficient, streaming query generator with MySQLdb
from MySQLdb.cursors import SSDictCursor
def iterate_query(query, connection, arraysize=1):
c = connection.cursor(cursorclass=SSDictCursor)
c.execute(query)
while True:
nextrows = c.fetchmany(arraysize)
if not nextrows:
break
@Odame
Odame / TimestampUtils.java
Created January 28, 2017 12:59 — forked from kristopherjohnson/TimestampUtils.java
Methods for generating ISO 8601 timestamps in Java/Android
package net.kristopherjohnson.util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
/**
* Methods for dealing with timestamps