Skip to content

Instantly share code, notes, and snippets.

View dzolnai's full-sized avatar

Dániel Zolnai dzolnai

  • Egeniq
  • Budapest
View GitHub Profile
@dzolnai
dzolnai / cadvisor
Last active February 26, 2016 14:41
cAdvisor init.d service
#!/bin/sh
### BEGIN INIT INFO
# Provides: cadvisor
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
@dzolnai
dzolnai / simplex.h
Created January 17, 2017 18:16
Simplex solver article - gist 1
typedef struct __attribute__((packed)) Tableau {
int rows, columns;
float matrix[MAX_ROWS * MAX_COLS];
bool dual_program;
} Tableau_t;
Tableau_t *tableau;
@dzolnai
dzolnai / SimplexRS.java
Last active January 17, 2017 18:17
Simplex solver article - gist 2
ScriptC_simplex script = new ScriptC_simplex(renderScript);
ScriptField_Tableau tableau = new ScriptField_Tableau(renderScript, 1);
int rowCount = data.length;
int columnCount = data[0].length;
tableau.set_rows(0, rowCount, false);
tableau.set_columns(0, columnCount, false);
tableau.set_dual_program(0, minimize, false);
tableau.set_matrix(0, data, false);
// Copy all values at once to the allocated memory of the struct.
tableau.copyAll();
@dzolnai
dzolnai / SimplexRS.java
Created January 17, 2017 18:27
Simplex solver article - gist 3
Type solutionVectorType = new Type.Builder(renderScript, Element.F32(renderScript)).setX(script.get_MAX_COLS()).create();
Type resultSizeType = new Type.Builder(renderScript, Element.I32(renderScript)).create();
script.set_solution_vector(arrayAllocation);
script.set_result_size(resultSizeAllocation);
script.invoke_solve();
float[] solutionVector = new float[script.get_MAX_COLS()];
arrayAllocation.copyTo(solutionVector);
int[] resultSizeVector = new int[1];
resultSizeAllocation.copyTo(resultSizeVector);
@dzolnai
dzolnai / simplex.c
Last active January 17, 2017 18:32
Simples solver article - gist 4
#pragma version(1)
#pragma rs java_package_name(com.egeniq.lpsolver.renderscript)
#pragma rs_fp_full
#include "simplex.rsh"
@dzolnai
dzolnai / simplex.h
Created January 17, 2017 18:42
Simplex solver article - gist 5
#define DEBUG true
#if DEBUG
#define LOG(msg, param) rsDebug(msg, param)
#else
#define LOG(msg, param)
#endif
@dzolnai
dzolnai / simplex.c
Created January 17, 2017 18:46
Simplex solver article - gist 6
for (int j = start_index; j < end_index; j++) {
float value = get_element(tableau, tableau->rows - 1, j);
rsSetElementAt_float(solution_vector, value, j - start_index);
}
rsSetElementAt_int(result_size, end_index - start_index, 0);
@dzolnai
dzolnai / BaseGridFragment.kt
Created May 23, 2018 13:46
A BaseGridFragment contains a VerticalGridSupportFragment which is modified to allow focus to escape it.
abstract class BaseGridFragment : Fragment() {
private var lifecycleCallbacks: FragmentManager.FragmentLifecycleCallbacks? = null
/**
* If your fragment contains a VerticalGridSupportFragment, it automatically includes a search button you can disable.
* However, the focus search listener is not disabled, and it does conflict with our implementation for showing the menu.
* Don't forget to save a reference to the callbacks to unsubscribe when destroying the fragment.
*/
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
val recognizerIntent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH)
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM)
// Prefer dutch language for recognition
recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "nl-NL")
// Display text for the user as hint until results are available (only in overlay mode)
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak to search...")
// Accept partial results if they come
recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true)
@dzolnai
dzolnai / AnimatingDialogFragment.kt
Created May 23, 2018 15:01
DialogFragment which can have hide animations
/**
* Dialog Fragment with hide animations
*/
class AnimatingDialogFragment : DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setStyle(DialogFragment.STYLE_NO_FRAME, R.style.TvTheme_Dialog)
}