Skip to content

Instantly share code, notes, and snippets.

View CJNE's full-sized avatar

Johan Isacsson CJNE

View GitHub Profile
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play mediaStorage="true">careable-fallback-system_unavailable-sv</Play>
<Hangup/>
</Response>
{
"id": 11,
"name": "belkyla",
"loc": "vinkallare",
"values": [
{
"id": "11-91-0-slowRefresh",
"nodeId": 11,
"commandClass": 91,
"commandClassName": "Central Scene",
@CJNE
CJNE / js
Last active December 1, 2015 07:59
Projection based on value in document
//Structure of documents in collection:
{
_id: 1,
name: "Some name",
versions: [
{
version: 1,
data: {}
},
@CJNE
CJNE / gist:24e0baaceebc0cd9cfb4
Last active August 29, 2015 14:06
Angular $q and file writer stream, how to wait until all chunks are written?
//The problem: this function is supposed to return a promise that is resolved when all chunks have been written
//but the promise is resolved after the first chunk has been written (after line 28)
//The intention is to resolve the promise on line 21
writeAt: function(fileName, chunks) {
var def = $q.defer();
rootDir.getFile(fileName, {create: true}, function(fileEntry) {
var totalBytesWritten = 0;
var writeChunk = function(fileWriter, chunk) {
console.log("Writing chunk at "+chunk.offset+" length "+chunk.data.byteLength);
@CJNE
CJNE / recipe
Last active August 29, 2015 14:03
Setting hostname example
instance_type = `curl -s http://169.254.169.254/latest/meta-data/instance-type`
instance_type.gsub!(".","")
env = node[:aws_hostname][:env]
domain = "abc.com"
execute "generate random hostname" do
command "echo $(( $RANDOM % 1000 )) > /etc/randomhost"
not_if { ::File.exists?("/etc/randomhost")}
end
random = `cat /etc/randomhost`
hostname = "aws#{env}#{instance_type}#{random.strip}"
@CJNE
CJNE / added categories to the index
Last active August 29, 2015 14:01
mongo indexing help, nscanned is very large when skip is a large number
{
"cursor": "BtreeCursor game_1_publishedAt_-1_setId_1_creatorLevel_1_categories_1",
"isMultiKey": true,
"n": 20,
"nscannedObjects": 20020,
"nscanned": 33224,
"nscannedObjectsAllPlans": 60061,
"nscannedAllPlans": 73267,
"scanAndOrder": false,
"indexOnly": false,
class Picture < ActiveRecord::Base
has_many :imagables_pictures
has_many :imagables, :through => :imagables_pictures
end
class ImagablesPicture < ActiveRecord::Base
belongs_to :picture
belongs_to :imageable, :polymorphic => true
end