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 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 / 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 / pylooper.py
Created June 9, 2018 21:01
Python serial sending character in loop
import serial
import time
def main():
ser = serial.Serial('/dev/ttyUSB0', 230400, timeout=1)
print(ser.name)
count = 0
while True:
@rwoloszyn
rwoloszyn / serialloop.sh
Last active June 9, 2018 21:03
Bash serial (tty) looper
#!/bin/bash
DEVICE=/dev/ttyUSB0
BAUDRATE=230400
echo "=======SETTINGS========="
echo "port: $DEVICE"
echo "spped: $BAUDRATE"
echo "========================"
@rwoloszyn
rwoloszyn / forms.py
Created June 20, 2018 22:48
Custom label for ModelChoicesField in django framework
class SimpleProjectModelChoicesField(ModelChoiceField):
def label_from_instance(self, obj):
return '{name}'.format(name=obj.name)
class CourseForm(ModelForm):
project = SimpleProjectModelChoicesField(queryset=Project.objects.filter(is_active=True))
def __init__(self, *args, **kwargs):
self.request = kwargs.pop("request")