Skip to content

Instantly share code, notes, and snippets.

View fearphage's full-sized avatar
⌨️
Cache rules everything around me.

Phred Lane fearphage

⌨️
Cache rules everything around me.
View GitHub Profile
@fearphage
fearphage / .gitconfig
Last active November 26, 2018 15:13
When you need to save the code before you save yourself, git fire.
[alias]
fire = !"f() { \
local current_branch=$(basename \"$(git symbolic-ref HEAD)\"); \
local new_branch=fire-${current_branch}-$(git config user.email)-$(date +%s) \
local message; \
if [ -z \"$1\" ]; then \
message=\"fire commit from $current_branch\"; \
else \
message=\"$*\"; \
fi; \
@fearphage
fearphage / tests.js
Created May 13, 2016 13:06 — forked from jhartikainen/tests.js
Example of stubbing a complex object
describe('something', function() {
beforeEach(function() {
this.getAttributeStub = sinon.stub(Xrm.Page, 'getAttribute');
});
afterEach(function() {
this.getAttributeStub.restore();
});
it('tests something', function() {
@fearphage
fearphage / System Design.md
Created May 3, 2016 16:58 — forked from vasanthk/System Design.md
System Design Cheatsheet

#System Design Cheatsheet

Picking the right architecture = Picking the right battles + Managing trade-offs

##Basic Steps

  1. Clarify and agree on the scope of the system
  • User cases (description of sequences of events that, taken together, lead to a system doing something useful)
    • Who is going to use it?
    • How are they going to use it?

Dropbox has a long-standing bug with changing case of files and directories. This is a work around.

It renames the directoy name to name+1 and then to lowercase name.

Example

  1. CatPants is renamed to CatPants1
  2. CatPants1 is then renamed to catpants
@fearphage
fearphage / ajax-post.js
Last active October 28, 2015 19:33 — forked from segdeha/ajax-post.js
Smallest possible Ajax implementation of POST requests (187 characters)
function p(u,p,c){with(new XMLHttpRequest)open('POST',u),setRequestHeader('Content-type','application/x-www-form-urlencoded'),onreadystatechange=function(){3<readyState&&c(this)},send(p)}
@fearphage
fearphage / ffmpeg
Last active September 1, 2015 16:41 — forked from bnerd/ffmpeg
Encode RTMP input stream into multiple outputs with ffmpeg
ffmpeg -re -i rtmp://localhost/live/input_stream -acodec libfaac -ab 128k -vcodec libx264 -s 640x360 -b:v 500k -preset medium -vprofile baseline -r 25 -f flv rtmp://localhost/live/medium_500k -acodec libfaac -ab 128k -vcodec libx264 -s 480x272 -b:v 300k -preset medium -vprofile baseline -r 25 -f flv rtmp://localhost/live/medium_300k -acodec libfaac -ab 128k -c:v libx264 -s 320x200 -b:v 150k -preset:v fast -profile:v baseline -level 1.2 -r 25 -f flv rtmp://localhost/live/medium_150k -acodec libfaac -vn -ab 48k -f flv rtmp://localhost/live/audio_only
#!/usr/bin/env bash
# On OS X, use this script to generate an encrypted deployment key for Travis CI.
# Dependencies:
# gem install travis
# brew install coreutils
if [ $# -lt 1 ]; then
echo "usage: $0 <user>/<repo>"

This short code will show how to sync database file using Realm, but can be used for any file that you need to send to Wear (using Data API). It just takes any file, change it to Asset object and send it over to Wear device. Also it can be used Mobile->Wear, and Wear->Mobile.

When you need to sync database just call FileSender.syncRealm(context);, that is it!

DISCLAIMER "Proper" way would be to synchronize each transaction to DB, but it in most cases Wear is used very rarely comparing to mobile, so it would most likely cause a battery drain. My idea was to synchronize it only whene it is needed (so for example when app closes). If you want to make sure that you are using latest DB, just send trigger data using MessageAPI from Wear to Phone with ask of syncing over its database, or keep some timestapm of last edit and check it.

@fearphage
fearphage / gist:eb439159c7adfc327acd
Created January 7, 2015 21:51
Python's defaultdict
function defaultDict(constructor) {
return new Proxy({}, {
get: function(object, property) {
return property in object
? object[property]
: object[property] = constructor()
;
}
});
}