Skip to content

Instantly share code, notes, and snippets.

@jlaine
jlaine / lines.geojson
Last active September 4, 2017 09:26
GeoJSON lines
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jlaine
jlaine / dtls_srtp.py
Created February 6, 2018 00:12
DTLS-SRTP proof of concept in python
import base64
import cffi
ffi = cffi.FFI()
ffi.cdef("""
typedef struct bio_st BIO;
typedef struct bio_method_st BIO_METHOD;
typedef struct env_md_st EVP_MD;
typedef struct ssl_ctx_st SSL_CTX;
typedef struct ssl_method_st SSL_METHOD;
@jlaine
jlaine / pagination-page.ts
Last active November 2, 2020 09:35
Angular pagination - page
export class Page<T> {
count: number; // total number of items
next: string; // URL of the next page
previous: string; // URL of the previous page
results: Array<T>; // items for the current page
}
export function queryPaginated<T>(http: HttpClient, baseUrl: string, urlOrFilter?: string | object): Observable<Page<T>> {
let params = new HttpParams();
let url = baseUrl;
if (typeof urlOrFilter === 'string') {
// we were given a page URL, use it
url = urlOrFilter;
} else if (typeof urlOrFilter === 'object') {
// we were given filtering criteria, build the query string
Object.keys(urlOrFilter).sort().forEach(key => {
export class Pony {
id: number;
is_available: boolean;
name: string;
}
@Injectable()
export class PonyService {
baseUrl = 'http://localhost:8000/v1/ponies';
@Component({
selector: 'app-pony-list',
templateUrl: './pony-list.component.html',
styleUrls: ['./pony-list.component.css']
})
export class PonyListComponent {
filterForm: FormGroup;
page: Observable<Page<Pony>>
pageUrl = new Subject<string>();
<div class="container" [formGroup]="filterForm">
<div class="search-bar">
<input formControlName="search" placeholder="Search by pony name">
<select formControlName="is_available">
<option [value]="null">Is available?</option>
<option [value]="true">Yes</option>
<option [value]="false">No</option>
</select>
</div>
from urllib.parse import quote
def add_content_disposition_header(response, filename):
"""
Add an RFC5987 / RFC6266 compliant Content-Disposition header to an
HttpResponse to tell the browser to save the HTTP response to a file.
"""
try:
filename.encode('ascii')
HTTP/1.1 200 OK
Content-Disposition: attachment; filename="somefile.pdf"
Content-Length: 12345
Content-Type: application/pdf
HTTP/1.1 200 OK
Content-Disposition: attachment; filename*=utf-8''s%C3%B6mefil%C3%AA.xlsx"
Content-Length: 12345
Content-Type: application/pdf