Skip to content

Instantly share code, notes, and snippets.

View vaughnd's full-sized avatar

Vaughn Dickson vaughnd

View GitHub Profile
@vaughnd
vaughnd / wordpress_password_check_in_python.py
Created March 8, 2023 11:42
How to verify a wordpress password in Python 3
# use passlib (https://passlib.readthedocs.io/en/stable/index.html) which includes a recent implementation of phpass,
# the lib Wordpress uses
from passlib.hash import phpass
# 'password' hashed with a random 8 character salt for a number of rounds=13. Salt and rounds are encoded in the hash itself
# https://passlib.readthedocs.io/en/stable/lib/passlib.hash.phpass.html#format
# $P${rounds,6-bit integer encoded as char}{salt, 8 characters}{checksum}
wordpress_hashed_password='$P$BcT47uPjTpAPe6VtS8MeR4MECevpNb.'
# will return True, because it takes it's configuration salt + rounds from the hash above
@vaughnd
vaughnd / riot.js
Last active November 29, 2016 10:04
Improved RiotJS eventbus
// The core of this is using a single broker for event handling across the app in RiotControl._broker.
// Then all events are handled by riot.control.on and triggered by riot.control.trigger.
// Special handling is required in riot tags to ensure that events get mounted/unmounted along with the tag,
// else you end up with fns firing in the background
// =====================================
// event_helper.js
class RiotControl {
constructor() {
package com.vaughndickson.elasticsearch
import groovy.util.logging.Slf4j
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus
import org.elasticsearch.client.Client
import org.elasticsearch.client.transport.TransportClient
import org.elasticsearch.common.settings.ImmutableSettings
import org.elasticsearch.common.settings.Settings
import org.elasticsearch.common.transport.InetSocketTransportAddress
import org.springframework.beans.factory.DisposableBean
@vaughnd
vaughnd / gist:9246309
Created February 27, 2014 08:16
Atomic find-or-create in datomic
;; Schema
{:db/doc "Find or create tag atomically."
:db/ident :find-or-create-tag
:db/fn #db/fn {:lang "clojure"
:params [mydb n key value]
:code (when (empty? (d/q '[:find ?e :in $ ?ns ?key ?value :where
[?e :meta/tag-namespace ?n]
[?e :meta/tag-key ?key]
[?e :meta/tag-value ?value]]
@vaughnd
vaughnd / gist:5099299
Last active April 3, 2023 14:01
Clojure implementation of fuzzy string matching as you'd find in emacs ido, sublime text file find, etc.
(ns scratchpad.core
(:require [clojure.pprint :as pprint]))
(defn get-dataset
[file]
(with-open [rdr (clojure.java.io/reader file)]
(vec (line-seq rdr))))
(defn str-len-distance
;; normalized multiplier 0-1
@vaughnd
vaughnd / gist:5097612
Created March 6, 2013 08:23
Clojure lucene index search implementation with cache that refreshes every minute
(ns search-index
(:require [clucy.core :as clucy]
[clojure.core.cache :as cache]))
(def my-data [{:name "bob" :age 32 }
{:name "Susan" :age 24}])
;; refresh cache every minute
(def cache (atom (cache/ttl-cache-factory {} :ttl (* 60 1000))))
@vaughnd
vaughnd / gist:3759951
Created September 21, 2012 06:02
Bash script to run more than one process in parallel and kill all when exiting the script (via ctrl-c or kill)
#!/bin/bash
# kill all subshells and processes on exit
trap "kill 0" SIGINT
# start commands in subshells so all their spawn DIE when we exit
( process1 ) &
( process2 ) &
wait
@vaughnd
vaughnd / gist:3705861
Created September 12, 2012 10:40
Datomic user -> group memberships with extra data using many-to-many
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://user-groups3")
(d/create-database uri)
(def conn (d/connect uri))
(d/transact
conn
[{:db.install/_attribute :db.part/db
:db/id #db/id[:db.part/db]
:db/ident :user/name
@vaughnd
vaughnd / gist:3705762
Created September 12, 2012 10:17
Datomic user->group memberships
(use '[datomic.api :only (q db) :as d])
(def uri "datomic:mem://user-groups2")
(d/create-database uri)
(def conn (d/connect uri))
(d/transact
conn
[{:db.install/_attribute :db.part/db
:db/id #db/id[:db.part/db]
:db/ident :user/name