Skip to content

Instantly share code, notes, and snippets.

@AcidLeroy
AcidLeroy / find_max_foreach_user.py
Last active November 15, 2015 03:48
Finding Max of RDD Triplet for Each User
from pyspark import SparkContext, SparkConf
def reduce_by_max(rdd):
"""
Helper function to find the max value in a list of values i.e. triplets.
"""
max_val = rdd[0][2]
the_index = 0
for idx, val in enumerate(rdd):
@AcidLeroy
AcidLeroy / convert_jpgs_in_current_dir.sh
Created December 8, 2015 05:28
convert all jpgs to pngs
!#/bin/bash
find ./ -name *.jpg* -exec mogrify -format png *.jpg {} \;
@AcidLeroy
AcidLeroy / vector_conversion_example.pyx
Created April 8, 2016 00:50
Example of how to convert std::vector of doubles to memviews and back using Cython
from libcpp.vector cimport vector
cdef convert_memview_to_vector(double[::1] &mem):
cdef vector[double] arr
arr.reserve(mem.shape[0])
for i in mem:
arr.push_back(i)
return arr
cdef convert_vector_to_memview(vector[double] &vec):
@AcidLeroy
AcidLeroy / discovery_server.js
Created June 21, 2018 14:26
http with discovery channel
const express = require('express')
const app = express()
const DC = require('discovery-channel')
const crypto = require('crypto')
app.get('/', (req, res) => {
console.log('Received a request')
res.send('Hello World')
})
const port = 30000
@AcidLeroy
AcidLeroy / discovery_client.js
Created June 21, 2018 14:27
http discovery client
const DC = require('discovery-channel')
const crypto = require('crypto')
const http = require('http');
let id = process.argv[2]
if (!id) {
console.log('You must have an ID')
process.exit(1)
@AcidLeroy
AcidLeroy / get-user-and-post.js
Last active July 9, 2018 23:09
Exploring Functions
const {Either, IO} = require('monet')
const {compose, map} = require('ramda')
// Pretend to get a database entry
// getUser :: String -> IO ( JSON )
var getUser = username => IO(() => (username === 'Marge') ? {name: 'Marge Simpson', address: '123 Fake St'} : {error: 'user ' + username + ' not found!'})
// Pretend to upload some information
// uploadUser :: JSON -> IO ()
var uploadUser = user => IO(() => console.log('Uploading user: ', user.name, ' at address', user.address))
@AcidLeroy
AcidLeroy / bad_route.js
Created July 26, 2018 20:33
routes not working
var html = require('choo/html') // 1.
var choo = require('choo')
var app = choo() // 2.
app.route('/', function(state, emit) { // 3.
return html`
<body> <!-- 4. -->
Hello World
</body>
`
@AcidLeroy
AcidLeroy / encryption_nedb.ts
Created January 11, 2019 00:02
This demonstrates how you can encrypt data using libsodium-wrappers for the Nedb NoSQL database. The algorithm is xchacha20poly1305
import { generateKey, encryptDocument, decryptDocument, ready } from 'easy-doc-crypt'
import Datastore = require('nedb')
(async function() {
await ready()
const key = generateKey('MyPassword123')
function encrypt(serialized :string) {
console.log('encrypt')
let d = encryptDocument(key.secret, serialized)
@AcidLeroy
AcidLeroy / lens-sync-example.js
Created January 22, 2019 01:49
An incomplete example of syncing lenses
const PouchDB = require('pouchdb')
const tmp = require('tmp');
const assert = require('assert');
const R = require('ramda')
PouchDB.plugin(require('crypto-pouch'));
// Create a temporary directory
var tmpobj = tmp.dirSync();
let dbLoc = `${tmpobj.name + '/mydb'}`
console.log(`dbLoc = ${dbLoc}`)
14ww3NG4sotUQdJGttBGuuZqkgaG9f7ran https://explorer.blockstack.org/address/14ww3NG4sotUQdJGttBGuuZqkgaG9f7ran