Skip to content

Instantly share code, notes, and snippets.

Rafal Woloszyn rwoloszyn

Block or report user

Report or block rwoloszyn

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
@rwoloszyn
rwoloszyn / element_template.py
Created Aug 9, 2018
Django get element from m2m relation in django template
View element_template.py
{% with object.group_set.all|first as group %}
<li class="breadcrumb-item"><a href="{% url 'group_detail' group_id=view.kwargs.group_id %}">{{ group.name }}</a></li>
{% endwith %}
@rwoloszyn
rwoloszyn / forms.py
Created Jun 20, 2018
Custom label for ModelChoicesField in django framework
View forms.py
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")
@rwoloszyn
rwoloszyn / daysleft.js
Created Jun 19, 2018
Calculate days left in js (React native)
View daysleft.js
_getLeftActivationDays = (finishDate) => {
var endDate = new Date(finishDate);
var today = new Date();
var oneDay = 24 * 60 * 60 * 1000;
return Math.round(Math.abs((today.getTime() - endDate.getTime())/ oneDay));
}
@rwoloszyn
rwoloszyn / serialloop.sh
Last active Jun 9, 2018
Bash serial (tty) looper
View serialloop.sh
#!/bin/bash
DEVICE=/dev/ttyUSB0
BAUDRATE=230400
echo "=======SETTINGS========="
echo "port: $DEVICE"
echo "spped: $BAUDRATE"
echo "========================"
@rwoloszyn
rwoloszyn / pylooper.py
Created Jun 9, 2018
Python serial sending character in loop
View pylooper.py
import serial
import time
def main():
ser = serial.Serial('/dev/ttyUSB0', 230400, timeout=1)
print(ser.name)
count = 0
while True:
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);
@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;
@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);
}
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 / 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));
You can’t perform that action at this time.