Skip to content

Instantly share code, notes, and snippets.

View mlalic's full-sized avatar

Marko Lalic mlalic

  • Zoox
  • Seattle, WA
View GitHub Profile
@mlalic
mlalic / bindings.json
Last active July 12, 2023 17:24
Reviewable custom config
[
["f", "Show next/latest diffs", "setProposedDiffBounds()"],
["n", "Next unreviewed file", "nextUnreviewedFile()"],
["p", "Previous unreviewed file", "prevUnreviewedFile()"],
["shift+n", "Next changed file", "nextChangedFile()"],
["shift+p", "Previous changed file", "prevChangedFile()"],
[null, "Next visible file", "nextVisibleFile()"],
[null, "Previous visible file", "prevVisibleFile()"],
[null, "Next file", "nextFile()"],
@mlalic
mlalic / BackgroundColorSample.cpp
Last active March 9, 2023 02:33
A sample demonstrating how to obtain the background color that apps should use from a simple Win32 process, using only C++ and the base Windows SDK with no additional library support (such as C++/WinRT or WRL).
#include <windows.h>
#include <roapi.h>
#include <iostream>
#include <cwchar>
#include <string>
// For Windows.UI.ViewManagement.UISettings
#include <windows.ui.viewmanagement.h>
@mlalic
mlalic / TextScaleSample.cpp
Created August 24, 2018 02:02
A full sample for obtaining the current system text scale. It doesn't rely on any libraries (such as WRL or C++/WinRT) and uses only base Windows SDK APIs.
#include <windows.h>
#include <roapi.h>
#include <iostream>
#include <cwchar>
// For Windows.UI.ViewManagement.UISettings
#include <windows.ui.viewmanagement.h>
int main() {
@mlalic
mlalic / drops.rs
Created October 8, 2015 16:51
Unsafe double drop due to aliasing
use std::mem;
use std::ptr;
struct Foo;
impl Drop for Foo {
fn drop(&mut self) {
println!("Dropping Foo");
}
}
@mlalic
mlalic / keybase.md
Created December 19, 2014 22:43
Keybase identity confirmation

Keybase proof

I hereby claim:

  • I am mlalic on github.
  • I am mlalic (https://keybase.io/mlalic) on keybase.
  • I have a public key whose fingerprint is FC9C 2B32 9C4D C82A 665E D385 35E3 69DF 9555 6536

To claim this, I am signing this object:

@mlalic
mlalic / paginated_list_model_mixin.py
Created July 17, 2014 12:03
A mixin for DjangoRestFramework providing seamles pagination of list responses without enveloping the response in an extra JSON object.
from django.core.paginator import (
Paginator,
EmptyPage,
)
from rest_framework.templatetags.rest_framework import replace_query_param
from rest_framework.response import Response
class PaginatedListModelMixin(object):
@mlalic
mlalic / multi_serializer_mixin.py
Created July 13, 2014 10:33
Mixin for the DjangoRestFramework ViewSet providing the ability to choose a different serializer based on the view action.
class MultiSerializerViewSetMixin(object):
"""
Mixin for the DRF ViewSet providing the ability to choose a different
serializer based on the view action.
Classes mixing it in need to provide the ``serializer_classes``
dictionary mapping an action to a serializer class.
If a particular action does not have a custom serializer attached to it,
the mixin delegates the call up the MRO (Method Resolution Order).
@mlalic
mlalic / fuzzy_foreign_key.py
Created June 17, 2014 16:23
A FuzzyAttribute for factory_boy to choose a random foreign key instance of a model.
class FuzzyForeignKeyChoice(factory.fuzzy.BaseFuzzyAttribute):
"""
A custom FuzzyAttribute for ``factory_boy`` which choses a random instance
of a model for a new instance's field value.
"""
def __init__(self, model):
self.model = model
def get_queryset(self):
"""
@mlalic
mlalic / filter_model_mixin.py
Last active January 30, 2024 08:47
A mixin for ``django-rest-framework``providing the possibility to filter the queryset based on query parameters.
from django.db.models import fields as django_fields
class FilteredModelViewSetMixin(object):
"""
A mixin providing the possibility to filter the queryset based on
query parameters.
The mixin overrides the ``get_queryset`` method to return the original
queryset additionally filtered based on the query string parameters.
@mlalic
mlalic / pwgen.py
Created May 26, 2014 09:37
A simple random password generator CLI application. Mostly created for the purpose of testing the click package (http://click.pocoo.org/)
import click
import string
import random
def _randomize(alphabet, count):
"""Return a random string consisting of characters from the alphabet.
The length of the returned string should be ``count``.
"""
rng = random.SystemRandom()