Skip to content

Instantly share code, notes, and snippets.

View rwoloszyn's full-sized avatar

Rafal Woloszyn rwoloszyn

View GitHub Profile
@rwoloszyn
rwoloszyn / controllers.js
Created June 27, 2016 17:19
Add checkbox as control in leaflet 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"/>Automatic fit to bounds</form>';
return div;
};
autoZoomCheckbox.addTo(map);
@rwoloszyn
rwoloszyn / controllers.js
Created June 27, 2016 17:19
Add custom control button to leafletmap
//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 June 27, 2016 17:30
Place control in top of ZoomControl in Leaflet
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 / HashCardAdapter.java
Created August 23, 2016 19:02
Enum with integer value
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 / SettingsTest.java
Created October 3, 2016 11:45
Reset singleton field during JUnit tests, roboelectric junit tests
@After
public void teaddown() {
setting.clear();
resetSingleton(ErgoSettings.class, "sInstance");
}
public static void resetSingleton(Class clazz, String fieldName) {
Field instance;
try {
@rwoloszyn
rwoloszyn / MapControlsLayer.java
Created October 12, 2016 18:47
Reduce decimal points number for double value
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 / gzipsinkTest.java
Created April 7, 2017 12:57
Test Okio GzipSink
@Test
public void testGzipSource() throws IOException {
String original = "Some super super long string.Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string." +
"Some super super long string.";
@rwoloszyn
rwoloszyn / MapsActivity.java
Created April 9, 2017 15:45
Switch off UI in Google maps Android
//Done in a MapFragment
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
UiSettings mapUiSettings = mMap.getUiSettings();
mapUiSettings.setCompassEnabled(false);
mapUiSettings.setZoomControlsEnabled(false);
mapUiSettings.setMapToolbarEnabled(false);
}
@rwoloszyn
rwoloszyn / gist:8a6abcb121ad3049b84ea8bb3236a50b
Created September 22, 2017 00:04
Is this some kind of C struct alocation, Why not malloc ?
*ptr = '\n';
ptr++;
*ptr = '\n';
ptr++;
base = (PacketHdrBase*)ptr;
@rwoloszyn
rwoloszyn / gist:e928a619b3f0e4fe26f11872e8586653
Created November 16, 2017 22:24
STM32F103 I2C BUSY FLAG Fix
GPIO_InitTypeDef GPIO_I2CInitStructure;
/*Workaround p26 errata STM32F103*/
__HAL_I2C_DISABLE(&hi2c1);
//OD HIGHG
GPIO_I2CInitStructure.Pin = I2C_SCL_PIN | I2C_SDA_PIN;
GPIO_I2CInitStructure.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_I2CInitStructure.Pull = GPIO_PULLUP;
HAL_GPIO_Init(I2C_PORT, &GPIO_I2CInitStructure);
HAL_GPIO_WritePin(I2C_PORT, I2C_SCL_PIN, GPIO_PIN_SET);
HAL_GPIO_WritePin(I2C_PORT, I2C_SDA_PIN, GPIO_PIN_SET);