Skip to content

Instantly share code, notes, and snippets.

@vote539
vote539 / ot.lua
Last active July 24, 2021 14:10
An implementation of operational transformation in Lua, designed for integration with Redis. See https://blog.sffc.xyz/post/182052412225/operational-tranformation-in-redis
-- Copyright (c) 2016, Shane Carr (ISC License)
--
-- Permission to use, copy, modify, and/or distribute this software for any
-- purpose with or without fee is hereby granted, provided that the above
-- copyright notice and this permission notice appear in all copies.
--
-- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
-- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
-- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
-- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@vote539
vote539 / sqlite_insert_default.php
Created July 22, 2013 01:22
Example implementation of inserting default values to SQLite fields given null values without changing your SQLite statement query.
<?php
// the name of your table
$table = "foobar";
// an array of your field names with default values
$fields = array(
"foo" => 5,
"bar" => "(date(now))"
);
@vote539
vote539 / changeTitleInNavigationView.js
Last active January 2, 2016 19:29
Permanently resets the title associated with a view in a Sencha Touch Navigation View.
/*
DESCRIPTION
===========
Permanently resets the title associated with a view in a Sencha Touch
Navigation View.
USAGE
=====
@vote539
vote539 / GetByXType.js
Last active December 21, 2015 00:08
Add an Ext.getByXType function. Returns an array of all components having the specified xtype (global search from root). Tested in Sencha Touch 2.
/*
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
@vote539
vote539 / UrlEncodeWriter.js
Last active December 20, 2015 01:09
Sends data from your Sencha Touch or Ext JS proxy to your server using traditional POST variables (instead of JSON or XML).
/*
Send data to the server as POST parameters. Refer to the documentation for {@link Ext.data.writer.Json}
for more details on proxy writers. Use "urlencode" as the writer type. For example, your store might
look something like this:
Ext.define('App.store.ExampleStore', {
extend: 'Ext.data.Store',
requires: [
'App.model.ExampleModel'
@vote539
vote539 / UpdatingSlider.js
Last active December 20, 2015 00:29
A Sencha Touch slider that displays the current value in a text field, updating automatically when the slider is moved/dragged/changed.
/*
Do the following when you make your slider:
myUpdatingSlider.down("#UpdatingSliderField").setValue(startValue);
myUpdatingSlider.down("#UpdatingSliderLabel").setHtml(startValue);
Sample CSS:
.slider-label{
font-size: 2em;
@vote539
vote539 / backbone-forward.js
Created July 8, 2013 09:00
My implementation of nested models for Backbone.js. Read more at http://codrspace.com/vote539/nested-models-and-collections-in-backbone-js/
Backbone.Model.prototype.forward = function (attribute, subModel, options) {
var self = this; // parent model
var property = (options && options.property) ?
options.property : attribute;
self[property] = subModel; // save the subModel in the specified property
subModel.set(self.get(attribute)); // add any existing data to the subModel
self.on("change:" + attribute, function(model, value, options){
subModel.set(value, options);
});
@vote539
vote539 / flexbox_supported.js
Last active August 29, 2015 14:24
Tiny, lightweight function to detect Flexbox support.
// Expanded
var flexboxSupported = (function(){
var prop = "flex-basis:1px";
var el = document.createElement("div");
var prefixes = ["", "-webkit-", "-moz-", "-o-", "-ms-"];
for(var i=0; i<prefixes.length; i++){
el.style.cssText += prefixes[i]+prop;
if(!!el.style.length) return true;
}
return false;