Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
"""
Monitor downtime of url:
>>> python monitor_downtime.py http://www.google.com
200
200
200
200
200
@skyjur
skyjur / gist:6765347
Last active December 24, 2015 07:39
Create copy of django model instance
def create_model_instance_copy(obj, **kwargs):
model = type(obj)
fields = [field for field in model._meta.fields if not field.primary_key]
initial = dict((field.get_attname(), field.value_from_object(obj)) for field in fields)
initial.update(**kwargs)
return model.objects.create(**initial)
@skyjur
skyjur / gist:10106924
Created April 8, 2014 10:14
Big refactoring
I want to propose a big big refactoring to make our package look like a nice python package.
tictrac -> tt
core -> tt/core
services/sync/<service> -> tt/services
services/sync/*.py -> tt/sync
services/* -> tt/sync (merge services/*.py with services/sync/*.py)
scripts/management -> tt/management
config -> tt/config
<other-apps> -> tt/<pther-apps>
@skyjur
skyjur / 0_reuse_code.js
Created October 14, 2015 15:58
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@skyjur
skyjur / about.md
Last active October 6, 2017 11:24
Minimal implementation for requirejs to load bundles produced by typescript

TypeScript allows to bundle output into a single file using outFile compiler option.

This can be very useful to create single file bundle for web and you might not even need webpack for more simple applications.

One problem that needs to be resolved is module-loader. If we use "module": "amd" compiler option, typescript output will use requirejs specification to define modules. Full requirejs specification is a bit longer, and includes asynchronous script loading. Since we don't need asynchronous script loading we can make simplified implementation. One such simplified implementation of requirejs specs is almondjs.

@skyjur
skyjur / schema.ts
Created October 15, 2017 08:56
schema to static magic
export const tString : 'string' = 'string';
export const tNumber : 'number' = 'number';
export interface TypeMap {
'number': number;
'string': string
}
export type Schema = {
[fieldName: string]: {type: "string" | "number"}
@skyjur
skyjur / schema.ts
Created October 15, 2017 08:56
schema to static magic
export const tString : 'string' = 'string';
export const tNumber : 'number' = 'number';
export interface TypeMap {
'number': number;
'string': string
}
export type Schema = {
[fieldName: string]: {type: "string" | "number"}
@skyjur
skyjur / snips.ts
Created November 8, 2017 04:20
js utils
export function getPath(url: string) {
return url
.replace(/^(http[s]?:)?\/\/[^/#?]+/, '') // remove origin
.replace(/[?#].*$/, '') // remove querystring or hash
}
export function getUrlParams(url: string) : {[key: string]: string} {
if(url.indexOf('?') !== -1) {
return parseQueryString(url.split('?')[1]);
@skyjur
skyjur / di.ts
Last active November 11, 2017 03:24
Primitive dependency injection with React
import { Component, Children } from "react";
const containerKey = 'container';
interface ServiceResolver {
get(serviceIdentifier: string): any;
}
export class Container implements ServiceResolver {
private factories: {[serviceIdentifier: string]: ()=>any} = {};
@skyjur
skyjur / api.ts
Last active December 26, 2017 13:20
Record/Replay api calls
class Bookshop {
api = BookshopTransportApi;
async findBookByName(name: string) {
val result = await this.api.call({
collection: 'books',
query: {name: id}
});
// process json result, return Book instance
}