Skip to content

Instantly share code, notes, and snippets.

Avatar

Rafal Woloszyn rwoloszyn

View GitHub Profile
@rwoloszyn
rwoloszyn / MapControlsLayer.java
Created Oct 12, 2016
Reduce decimal points number for double value
View MapControlsLayer.java
DecimalFormat df = new DecimalFormat("#.####");
df.setRoundingMode(RoundingMode.CEILING);
double newLat = Double.valueOf(df.format(coordinates.latitude));
double newLong = Double.valueOf(df.format(coordinates.longitude));
@rwoloszyn
rwoloszyn / SettingsTest.java
Created Oct 3, 2016
Reset singleton field during JUnit tests, roboelectric junit tests
View SettingsTest.java
@After
public void teaddown() {
setting.clear();
resetSingleton(ErgoSettings.class, "sInstance");
}
public static void resetSingleton(Class clazz, String fieldName) {
Field instance;
try {
@rwoloszyn
rwoloszyn / HashCardAdapter.java
Created Aug 23, 2016
Enum with integer value
View HashCardAdapter.java
public enum CardViewType {
SUBSCRIBED(1),
REJECTED(2),
NEW(3);
private int value;
private static Map<Integer, CardViewType> map = new HashMap<>();
CardViewType(int value) {
this.value = value;
@rwoloszyn
rwoloszyn / controllers.js
Created Jun 27, 2016
Place control in top of ZoomControl in Leaflet
View controllers.js
map.zoomControl.removeFrom(map);
// create the control
var autoZoomCheckbox = L.control({position: 'topleft'});
autoZoomCheckbox.onAdd = function (map) {
var div = L.DomUtil.create('div', 'command');
div.innerHTML = '<form><input id="command" type="checkbox"/>Auto fit bounds</form>';
return div;
};
autoZoomCheckbox.addTo(map);
@rwoloszyn
rwoloszyn / controllers.js
Created Jun 27, 2016
Add custom control button to leafletmap
View controllers.js
//Add center result control button
L.easyButton({
states: [{
stateName: 'zoom-to-forest',
icon: 'glyphicon glyphicon-screenshot',
title: 'Center map to heat results',
onClick: function(btn, map) {
if (typeof $scope.heatLayer != 'undefined'
&& typeof $scope.maxGlobalHeat != 'undefined') {
map.setView($scope.maxGlobalHeat, 10);
@rwoloszyn
rwoloszyn / controllers.js
Created Jun 27, 2016
Add checkbox as control in leaflet map
View controllers.js
// create the control
var autoZoomCheckbox = L.control({position: 'topleft'});
autoZoomCheckbox.onAdd = function (map) {
var div = L.DomUtil.create('div', 'command');
div.innerHTML = '<form><input id="command" type="checkbox"/>Automatic fit to bounds</form>';
return div;
};
autoZoomCheckbox.addTo(map);
@rwoloszyn
rwoloszyn / controllers.js
Created May 31, 2016
Create unique list in JS with underscorelibrary
View controllers.js
function addFailedTask(taskID){
if(taskID != null){
$scope.failedTaskList.push(taskID);
}
$scope.failedTaskList = _.uniq($scope.failedTaskList);
}
@rwoloszyn
rwoloszyn / leaflet-custom-markers.js
Created Apr 28, 2016
draw point in some distance betwen two geo points lat/lon
View leaflet-custom-markers.js
_calculateOffset: function(bearing_angle, radius){
//Calculate destination point based on bearing and distance
//http://www.movable-type.co.uk/scripts/latlong.html
var d2r = L.LatLng.DEG_TO_RAD; //simple convert do radians
var r2d= L.LatLng.RAD_TO_DEG; //simple convert to degrees
var radius = radius/1500;
var lat = this._latlng.lat * d2r;
var lng = this._latlng.lng * d2r;
var angle = bearing_angle * d2r;
var R = 6372.795477598;
@rwoloszyn
rwoloszyn / controllers.js
Created Apr 28, 2016
Remove item from array using underscore.js library
View controllers.js
$scope.excludedTrips = _.reject($scope.excludedTrips, function(objArr){
return objArr.id == event.id;
});
@rwoloszyn
rwoloszyn / main_single_chart_card.xml
Created Apr 10, 2016
Align layouts on the left and right edeges
View main_single_chart_card.xml
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/no_answer_image"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentLeft="true"
android:layout_marginLeft="5dp"