Skip to content

Instantly share code, notes, and snippets.

Luke Horvat lukehorvat

Block or report user

Report or block lukehorvat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lukehorvat
lukehorvat / NumberPickerDialogPreference.java
Last active Jan 4, 2018
An Android preference class that provides a user with the means to select an integer from a NumberPicker and persist it. (License: MIT License)
View NumberPickerDialogPreference.java
package com.lukehorvat;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.NumberPicker;
@lukehorvat
lukehorvat / SeekBarDialogPreference.java
Last active Dec 10, 2015
An Android preference class that provides a user with the means to select an integer from a SeekBar and persist it. (License: MIT License)
View SeekBarDialogPreference.java
package com.lukehorvat;
import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.DialogPreference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SeekBar;
@lukehorvat
lukehorvat / ConcurrentImageBrightnessNormalizer.cs
Last active Dec 11, 2015
An example of concurrent image brightness normalization in C#.
View ConcurrentImageBrightnessNormalizer.cs
//determine the brightness range of this thread's image strip
Tuple brightnessRange = GetImagePartBrightnessRange(image, startX, startY, finishX, finishY);
//update the global brightness range of the entire image
lock (_lock)
{
minBrightness = Math.Min(minBrightness, brightnessRange.Item1);
maxBrightness = Math.Max(maxBrightness, brightnessRange.Item2);
}
@lukehorvat
lukehorvat / gp_decision_tree.py
Created Jan 15, 2013
An introduction to genetic programming with esec demonstrating decision tree induction.
View gp_decision_tree.py
from esec import esdl_eval
from esec.species.tgp import Instruction, DecisionInstructionWithState
from esec.landscape.tgp import TGPFitness
#define the attributes of a Saturday morning
OUTLOOK = ('SUNNY', 'OVERCAST', 'RAIN')
HUMIDITY = ('HIGH', 'NORMAL')
WINDY = (True, False)
#define the state object to store attributes of a Saturday morning
@lukehorvat
lukehorvat / decision_instructions.py
Last active Dec 11, 2015
[Blog post code] Genetic Programming with esec: An Introductory Example
View decision_instructions.py
instructions = [
DecisionInstructionWithState(lambda fitness_case: 1 if fitness_case.outlook == 'SUNNY' else (2 if fitness_case.outlook == 'OVERCAST' else 3), param_count=3, name='OUT'),
DecisionInstructionWithState(lambda fitness_case: 1 if fitness_case.humidity == 'HIGH' else 2, param_count=2, name='HUM'),
DecisionInstructionWithState(lambda fitness_case: 1 if fitness_case.windy else 2, param_count=2, name='WIND'),
]
@lukehorvat
lukehorvat / sibelius_fixer.bat
Created Jan 15, 2013
Batch file for fixing WAVs exported from Sibelius. Uses SoX to process files.
View sibelius_fixer.bat
cd %~dp0
mkdir converted
FOR %%A IN (%*) DO (
sox %%A "converted/%%~nxA" reverse trim 4.3 reverse trim 0.3 gain -n -1
lame -V7 converted/%%~nxA
)
pause
@lukehorvat
lukehorvat / excel-grid-plugin.js
Last active Mar 8, 2019
An Ext JS 4 grid plugin that provides Microsoft Excel-esque cell navigation and editing via keyboard. (License: MIT License)
View excel-grid-plugin.js
var newGridCellValue = '',
deleteGridCellValue = false;
Ext.define('ExcelCellEditing', {
extend: 'Ext.grid.plugin.CellEditing',
alias: 'plugin.excelcellediting',
initEditTriggers: function () {
var me = this;
@lukehorvat
lukehorvat / routes.html.erb
Created Sep 1, 2013
List all of the routes in your Ruby on Rails application in a nicely-formatted HTML table. Well-suited to those times when you're building an API and need an "auto-updating" reference page of application endpoints that you can share with others.
View routes.html.erb
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Routes</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
@lukehorvat
lukehorvat / interceptors.coffee
Last active Dec 23, 2015
An example of how to use request/response interceptors in AngularJS 1.2 for consistent API interactions. This code does two things: 1) Automatic injection of the user auth token in all API requests. 2) Automatic event firing when the user receives an API response indicating a 401 (unauthorised) request.
View interceptors.coffee
.config ($httpProvider) ->
$httpProvider.interceptors.push ($q, $rootScope, apiUrl, authToken) ->
request: (config) ->
# Intercept API requests and inject the auth token.
config.headers["X-Auth-Token"] = authToken if config.url.indexOf(apiUrl) is 0 and authToken?
config or $q.when config
responseError: (response) ->
# Intercept unauthorised API responses and fire an event.
@lukehorvat
lukehorvat / es6-map-to-object-literal.js
Last active Nov 1, 2019
Convert ES6 Map to Object Literal
View es6-map-to-object-literal.js
let map = new Map();
map.set("a", 1);
map.set("b", 2);
map.set("c", 3);
let obj = Array.from(map).reduce((obj, [key, value]) => (
Object.assign(obj, { [key]: value }) // Be careful! Maps can have non-String keys; object literals can't.
), {});
console.log(obj); // => { a: 1, b: 2, c: 3 }
You can’t perform that action at this time.