Skip to content

Instantly share code, notes, and snippets.

View akorchev's full-sized avatar

Atanas Korchev akorchev

View GitHub Profile
function update(req, res) {
const { id, name, saying } = req.body;
Hero.findOne({ id })
.then(hero => {
hero.name = name;
hero.saying = saying;
hero.save().then(() => res.json(hero))
})
.catch(err => {
function update(req, res) {
const { id, name, saying } = req.body;
Hero.findOne({ id }, (err, hero) => {
if (err) {
res.status(500).send(err);
} else if (!hero) {
res.status(500).send("Hero not found");
} else {
hero.name = name;
interface Car {
}
interface Bus {
}
type Vehicle = Car | Bus;
function drive(vehicle: Vehicle): void {
switch (vehicle) {
(function($, undefined) {
$.ui5 = $.ui5 || {};
function DataSource(options) {
var that = this;
that.idMap = {};
$.extend(that, options);
}
var children = [];
for (var i = 0; i < a.length; ++i) {
children[i] = dom("li", a[i]);
}
return dom("ul", children);
$.ajax({
url: "http://example.com",
type: "POST",
data: '{"sqlcmd":"SELECT TOP 10 FROM table"}',
contentType: "application/json; charset=utf-8",
});
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.litSalesGridDataSource.Text = "<script>" & vbCrLf & _
"var oSales = [" & vbCrLf
For i As Int32 = 1 To 5
Select Case i
Case Is = 1
Me.litSalesGridDataSource.Text &= "{" & vbCrLf & _
"""SaleID"": """ & i & """," & vbCrLf & _
"""SaleDate"": """ & Format(CDate("01-Jan-2012"), "MM/dd/yyyy") & """," & vbCrLf & _
@akorchev
akorchev / gist:1191154
Created September 3, 2011 13:02
Active Record vs Unit of Work
// Active Record
var User = Model.define( {
id: "UserID",
transport: {
create: "create.php"
}
});
var user = new User();
user.set($("form").serialize());
(function() {
this.tmpl3 = function tmpl(str, data) {
var value = "var out = ''; out+=" + "'" +
str.replace(/[\r\t\n]/g, " ")
.replace(/'(?=[^%]*%>)/g,"\t")
.split("'").join("\\'")
.split("\t").join("'")
.replace(/<%=(.+?)%>/g, "'; out += $1; out += '")
.split("<%").join("';")
(function() {
var cache = {};
this.tmpl2 = function tmpl(str, data) {
// Figure out if we're getting a template, or if we need to
// load the template - and be sure to cache the result.
var fn = !/\W/.test(str) ?
cache[str] = cache[str] ||
tmpl(document.getElementById(str).innerHTML) :