Skip to content

Instantly share code, notes, and snippets.

@joelash
joelash / app.js
Last active December 14, 2021 11:46
React Native Detect Backgrounding/Foregrounding
import React from 'react';
import {
AppState,
} from 'react-native';
import Expo from 'expo';
class App extends React.Component {
constructor(props) {
/**
* MQTT Bridge
*
* Authors
* - st.john.johnson@gmail.com
* - jeremiah.wuenschel@gmail.com
* - asher.friedman@gmail.com
*
* Copyright 2016
*
;; Async Lifecycle
(defn lifecycle-channel [component]
(let [tap-ch (async/chan)]
(-> (.-lifecycleChannel component)
:mult
(async/tap tap-ch))
tap-ch))
(defn with-lifecycle [klass]
(ns delay-chan
(:require [clojure.core.async :refer [>! <! put! chan timeout go alts!]))
(defonce model-chan (chan))
(defn delay-chan
"Take a channel to listen to and optional timeout. Returns a sleepy-chan
Will only publish latest message on sleepy-chan once per timeout."
[input-chan]
(let [output-chan (chan)]
(ns cowboy
(:import [javax.crypto Cipher SecretKey SecretKeyFactory]
[javax.crypto.spec DESedeKeySpec IvParameterSpec]
[org.apache.commons.codec.binary Base64 Hex]))
(def algo "DESede")
(def transformation "DESede/CBC/PKCS5Padding")
(defn bytes [s]
(.getBytes s "UTF-8"))
@joelash
joelash / gist:5767172
Last active December 18, 2015 10:18
notes from Neo4j tutorial on 6/12/2013

Neo4j in general

  • When store a join table structure in a graph database you just drop the join table and have a direct relationship
  • Usually start with drawing the graph on a whiteboard and then work from there
  • in general for speed want to avoid millions of relationships off of nodes, prefer lots of nodes over this. (But sometimes this is just necessary) (might be solved in 2.1)

Cypher

  • Commenting on something has (person) -commented-> (comment) -on-> (thing)
  • cypher is the sql like query language -> designed entirely for graphs with pattern matching for nodes and relationships
  • node is a circle and relationship is an arrow, so query is like ascii art for this (a) --> (b)
@joelash
joelash / chef_solo_bootstrap.sh
Created August 30, 2012 21:45 — forked from ryanb/chef_solo_bootstrap.sh
Bootstrap Chef Solo
#!/usr/bin/env bash
apt-get -y update
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline6-dev libyaml-dev
cd /tmp
wget ftp://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p125.tar.gz
tar -xvzf ruby-1.9.3-p125.tar.gz
cd ruby-1.9.3-p125/
./configure --prefix=/usr/local
make
make install
@joelash
joelash / gist:1125362
Created August 4, 2011 15:00
jruby-1.6.3 Digest#file bug when run with JRUBY_OPTS=--1.9
require 'pathname'
require 'digest'
`touch foo.txt`
path = Pathname.new 'foo.txt'
digest = Digest::MD5.new # digest type doesn't matter, see same problem with SHA1
digest.file path # this line throws an error when have JRUBY_OPTS=--1.9
require "rubygems"
require "jretlang"
class Arnie
def initialize
@channel = JRL::Channel.new
@consumer = JRL::Fiber.new
end
def start