Skip to content

Instantly share code, notes, and snippets.

View multinerd's full-sized avatar
💭
Nerding out

Multinerd multinerd

💭
Nerding out
View GitHub Profile
-- Convert Base64 value in a variable to varbinary:
declare @str varchar(20);
set @str = '3qAAAA==';
select cast(N'' as xml).value('xs:base64Binary(sql:variable("@str"))', 'varbinary(20)');
-- Convert binary value in a variable to Base64:
declare @bin varbinary(20);
set @bin = 0xDEA00000;
select cast(N'' as xml).value('xs:base64Binary(xs:hexBinary(sql:variable("@bin")))', 'varchar(20)');

Symbolic Breakpoint

Debugging Constraints
Symbol: UIViewAlertForUnsatisfiableConstraints
Debugger Action: po [[UIWindow keyWindow] _autolayoutTrace]
// MARK: - UIView Extension for Dance
@available(iOS 10.0, *)
extension UIView {
fileprivate struct DanceAssociatedKey {
static var dance = "dance_key"
}
public var dance: Dance {
@multinerd
multinerd / gist:a61d04622f1230cb19e5f1caaf52771e
Created October 10, 2017 21:35
Syncing data across multiple devices to a single db

Source: https://stackoverflow.com/questions/5035132/how-to-sync-iphone-core-data-with-web-server-and-then-push-to-other-devices

I've done something similar to what you're trying to do. Let me tell you what I've learned and how I did it.

I assume you have a one-to-one relationship between your Core Data object and the model (or db schema) on the server. You simply want to keep the server contents in sync with the clients, but clients can also modify and add data. If I got that right, then keep reading.

I added four fields to assist with synchronization:

  1. sync_status - Add this field to your core data model only. It's used by the app to determine if you have a pending change on the item. I use the following codes: 0 means no changes, 1 means it's queued to be synchronized to the server, and 2 means it's a temporary object and can be purged.
/// <summary>
/// Cleans paths of invalid characters.
/// </summary>
public static class PathSanitizer
{
/// <summary>
/// The set of invalid filename characters, kept sorted for fast binary search
/// </summary>
private readonly static char[] invalidFilenameChars;
/// <summary>

Developement Checklist

App.xaml(.cs)

  1. Override OnStartup and OnExit.
  • Create TempDirectory (if needed)
  • Implement InstanceChecker to prevent multiple instances of an application from running.
  • Setup CrashReporter events and handlers
public static class MvcHtmlHelpers
{
/// <summary>
/// Renders checkbox as one input (normal Html.CheckBoxFor renders two inputs: checkbox and hidden)
/// </summary>
public static MvcHtmlString BasicCheckBoxFor<T>(this HtmlHelper<T> html, Expression<Func<T, bool>> expression, object htmlAttributes = null)
{
var tag = new TagBuilder("input");
tag.Attributes["type"] = "checkbox";

// @class = "form-control"
// When using editortemplates, this class is important

  <div class="md-form">
    @Html.LabelFor(model => model.Date, htmlAttributes: new { @class = "" }, labelText: $"Date Of Incident (ex: {DateTime.Now.ToString(CultureInfo.CurrentCulture)})")
    @Html.EditorFor(model => model.Date, new { htmlAttributes = new { @class = "form-control", type = "text" } })
    @Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" })
  </div>
@multinerd
multinerd / 7-zip-default-extract.reg
Created June 17, 2018 05:32 — forked from zabbarob/7-zip-default-extract.reg
Make 7-Zip extract to folder when double-clicking archives. (based on http://superuser.com/a/447791)
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\7-Zip.001\shell]
@="extract"
[HKEY_CLASSES_ROOT\7-Zip.001\shell\extract]
@="Extract to Folder"
[HKEY_CLASSES_ROOT\7-Zip.001\shell\extract\command]
@="\"C:\\Program Files\\7-Zip\\7zG.exe\" x \"%1\" -o*"
[HKEY_CLASSES_ROOT\7-Zip.7z\shell]