Skip to content

Instantly share code, notes, and snippets.

View kuccello's full-sized avatar

Kristan Krispy Uccello kuccello

View GitHub Profile
@kuccello
kuccello / MainActivity.java
Last active August 28, 2023 10:14
An example MusicPlayer class that demonstrates how to use AudioFocus and a BroadcastReceiver to play audio cleanly on Android.
/*
Copyright 2013 Google Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
private AudioManager.OnAudioFocusChangeListener mOnAudioFocusChangeListener;
//…
mOnAudioFocusChangeListener = new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int focusChange) {
switch (focusChange) {
case AudioManager.AUDIOFOCUS_GAIN:
Log.i(TAG, "AUDIOFOCUS_GAIN");
// Set volume level to desired levels
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class DetectAndroidTV : MonoBehaviour {
public Text detectionText;
// Use this for initialization
void Start () {
function roundm(n, m) return math.floor(((n + m - 1)/m))*m end
-- Now we can change the returned value from getRandomPointInCircle to:
function getRandomPointInCircle(radius)
local t = 2*math.pi*math.random()
local u = math.random()+math.random()
local r = nil
if u > 1 then r = 2-u else r = u end
return roundm(radius*r*math.cos(t), tile_size),
static void quicksort(int[] a, int low, int high) {
if(low<high){
int p = partition(a,low,high);
quicksort(a,low,p-1);
quicksort(a,p+1,high);
}
}
static int partition(int[] a, int low, int high) {
int p = a[high];
static void insertSort(int[] a) {
for(int i=1;i<a.Length;++i) {
int x = a[i];
int j = i - 1;
while(j>=0 && a[j]>x){
a[j+1]=a[j];
--j;
}
a[j+1]=x;
}
/**
Given an array of integers, sort the array into a wave like array and return it,
In other words, arrange the elements into a sequence such that a1 >= a2 <= a3 >= a4 <= a5.....
Example
Given [1, 2, 3, 4]
One possible answer : [2, 1, 4, 3]
Another possible answer : [4, 1, 3, 2]
/***
Given an array of size n, find the majority element. The majority element is the element that appears more than floor(n/2) times.
You may assume that the array is non-empty and the majority element always exist in the array.
***/
public static int majorityElement(final List<Integer> a) {
HashMap<Integer,Integer> count = new HashMap<Integer,Integer>();
Integer largestKey = 0;
/**
Reverse bits of an 32 bit unsigned integer
Example 1:
x = 0,
00000000000000000000000000000000
=> 00000000000000000000000000000000
return 0
/**
Given an array A of integers and another non negative integer k, find if there exists 2 indices i and j such that A[i] - A[j] = k, i != j.
Example :
Input :
A : [1 5 3]
k : 2
Output :