Skip to content

Instantly share code, notes, and snippets.

Avatar

Rafal Woloszyn rwoloszyn

View GitHub Profile
@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 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
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 / 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 / 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 / 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));
View gzipsinkTest.java
@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 Apr 9, 2017
Switch off UI in Google maps Android
View MapsActivity.java
//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 Sep 22, 2017
Is this some kind of C struct alocation, Why not malloc ?
View gist:8a6abcb121ad3049b84ea8bb3236a50b
*ptr = '\n';
ptr++;
*ptr = '\n';
ptr++;
base = (PacketHdrBase*)ptr;
View gist:e928a619b3f0e4fe26f11872e8586653
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);