Skip to content

Instantly share code, notes, and snippets.

@vote539
vote539 / ot.lua
Last active Jul 24, 2021
An implementation of operational transformation in Lua, designed for integration with Redis. See https://blog.sffc.xyz/post/182052412225/operational-tranformation-in-redis
View ot.lua
-- 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 / flexbox_supported.js
Last active Aug 29, 2015
Tiny, lightweight function to detect Flexbox support.
View flexbox_supported.js
// 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;
@vote539
vote539 / changeTitleInNavigationView.js
Last active Jan 2, 2016
Permanently resets the title associated with a view in a Sencha Touch Navigation View.
View changeTitleInNavigationView.js
/*
DESCRIPTION
===========
Permanently resets the title associated with a view in a Sencha Touch
Navigation View.
USAGE
=====
@vote539
vote539 / GetByXType.js
Last active Dec 21, 2015
Add an Ext.getByXType function. Returns an array of all components having the specified xtype (global search from root). Tested in Sencha Touch 2.
View GetByXType.js
/*
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 / sqlite_insert_default.php
Created Jul 22, 2013
Example implementation of inserting default values to SQLite fields given null values without changing your SQLite statement query.
View sqlite_insert_default.php
<?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 / UrlEncodeWriter.js
Last active Dec 20, 2015
Sends data from your Sencha Touch or Ext JS proxy to your server using traditional POST variables (instead of JSON or XML).
View UrlEncodeWriter.js
/*
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 Dec 20, 2015
A Sencha Touch slider that displays the current value in a text field, updating automatically when the slider is moved/dragged/changed.
View UpdatingSlider.js
/*
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;
View backbone-forward.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);
});