Skip to content

Instantly share code, notes, and snippets.

@zelid
zelid / utils.py
Created May 19, 2012 14:37
Allow to create new model with related models in Flask-Peewee API call
def get_models_from_dictionary(model, field_dict):
if isinstance(model, Model):
model_instance = model
check_fks = True
else:
model_instance = model()
check_fks = False
models = [model_instance]
for field_name, value in field_dict.items():
field_obj = model._meta.fields[field_name]
public class Question
{
public int Id { get; set; }
public string Name { get; set; }
public List<Answer> Answers { get; set; }
public List<Comment> Comments { get; set; }
}
public class Answer
{
Post["/question"] = parameters =>
{
Question question = this.Bind();
return View["question.html", question];
};
<form action="/question" method="post">
<ul>
<li>
<input type="text" name="Name" value="Question Name" />
<input type="text" name="Id" value="1" />
</li>
<li>
<ul>
<li>
<input type="text" name="Answers[0].Name" value="Answer 1 Name" />
<form action="/question" method="post">
<ul>
<li>
<input type="text" name="Name" value="Question Name" />
<input type="text" name="Id" value="1" />
</li>
<li>
<ul>
<li>
<input type="text" name="Question[Answers][0].Name" value="Answer 1 Name" />
@zelid
zelid / gist:6965002
Last active August 3, 2023 17:23
Examples of BulkInsert for PostgreSQL, MySQL and MS SQL using ServiceStack OrmLite. Work in progress...
public static void BulkInsertNpgsql<T>(this IDbConnection dbConn, IEnumerable<T> list, IEnumerable<string> insertFields = null)
{
if (list == null) return;
if (list.Count() < 1) return;
var objWithAttributes = list.FirstOrDefault();
var modelDef = OrmLiteConfig.GetModelDefinition(objWithAttributes.GetType());
if (insertFields == null) insertFields = new List<string>();
import wx
import win32api
import win32gui
import win32con
from sciter import sapi
from sciter.capi.scdef import *
@zelid
zelid / test-image.html
Last active September 24, 2017 17:20
Strange IMG behaviour
<html>
<head>
<title></title>
<style>
body {
/* background-color: #404552; */
/* border-color: #404552; */
}
!
! Comments begin with a "!" character.
!
XTerm*background: black
XTerm*foreground: white
XTerm*cursorColor: white
XTerm*VT100.geometry: 80x25
! XTerm*faceName: Terminus:style=Regular:size=10
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Targets in ths file are to take a V8 context snapshot on build time.
# Created V8 context snapshot is used in
# third_party/WebKit/Source/bindings/core/v8/V8ContextSnapshot.{cpp|h}.
# to speedup creating a V8 context and setting up around it.
import("//tools/v8_context_snapshot/v8_context_snapshot.gni")