Skip to content

Instantly share code, notes, and snippets.

View drush's full-sized avatar

Darren Rush drush

View GitHub Profile
@drush
drush / db_export.rake
Created February 2, 2024 20:40
Rails Task to export a DB to mockdb.json compatible ith React-admin fakerest provider
# Utility for https://talysto.com/tech/groovestack applications
# Will export your current DB to a single JSON file that can be consumed directly
# by React-admin Fakerest adapter
# lib/tasks/db_export.rake
namespace :db do
desc 'Export all tables to a single JSON file, database-agnostic'
task export: :environment do
require 'json'
# Define an array of tables to exclude
@drush
drush / README.md
Created August 5, 2021 23:46 — forked from mrbar42/README.md
bash scripts to create VOD HLS stream with ffmpeg almighty (tested on Linux and OS X)

running:

bash create-vod-hls.sh beach.mkv

will produce:

    beach/
      |- playlist.m3u8
 |- 360p.m3u8
@drush
drush / most-used-commands.cli.sh
Last active January 14, 2020 16:51
Find the Command Line Utilities You Use the Most
history | awk '{CMD[$2]++;count++;}END { for (a in CMD)print CMD[a] " " CMD[a]/count*100 "% " a;}' | grep -v "./" | column -c3 -s " " -t | sort -nr | nl | head -n20
@drush
drush / chantest.go
Last active January 22, 2018 19:51
Buffered vs Unbuffered channel behavior in golang
package main
import (
"fmt"
"sync"
"time"
)
func main() {
// Bufferered channel. Remove the 50 to see how an unbuffered channel behaves differently
@drush
drush / gist:4590dd2c7057b1d807c3
Created July 28, 2015 20:55
Elasticsearch Scan & Scroll Proto
require 'mechanize'
a = Mechanize.new
body = a.post('http://localhost:9200/sbir_dom/Firm/_search?search_type=scan&scroll=1m', {
"query": {
"query_string": { "query": "name:z*" }
},
"_source": false, "fields": ["_id"], "size": 10
}.to_json).body
@drush
drush / delayed_job_threads.rb
Last active July 13, 2020 13:17
Run Delayed Job Worker as a Thread in Web Process
# Only run in server process, not console or rake tasks
if !Rails.const_defined?('Console') && !($0 =~ /rake$/) && !Rails.env.test?
Rails.application.config.after_initialize do
(1..2).each do |thread_id|
Thread.new {
Thread.current[:thread_name] = "DJ Web Worker Thread #{thread_id}"
ActiveRecord::Base.connection_pool.with_connection do |conn|
dj = Delayed::Worker.new
Rails.logger.warn "Starting #{Thread.current[:thread_name]}"
@drush
drush / heroku-dynos.rb
Last active September 11, 2017 17:05
Show a report of the current number of web and worker dynos and the stack used across all your Heroku apps.
apps = `heroku apps`.split("\n\n")[0].lines[1..-1].collect{|l| l.strip }
printf("%-20s %4s %4s\n", 'APP', 'WEB', 'BG')
apps.each{|a|
astats = `heroku ps -a #{a}`
info = `heroku apps:info -a #{a}`
access = `heroku access -a #{a}`
stack = info.scan(/Stack:\s+(.*)/).first.last rescue 'NA'
web, workers = (astats.match(/web\.\d/).size rescue 0), (astats.match(/worker\.\d/).size rescue 0)
printf("%-20s %4s %4s %20s\t#{access}\n", a, web, workers, stack)
}
@drush
drush / elasticsearch_install.sh
Last active December 13, 2015 23:19 — forked from rajraj/es.sh
Install elasticsearch on a fresh Centos6 box
cd ~
sudo yum update
sudo yum install java-1.7.0-openjdk.i686 unzip wget -y
wget http://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-0.20.5.zip -O elasticsearch.zip
export ES_HOME=/opt/elasticsearch
sudo unzip elasticsearch.zip -d $ES_HOME
rm elasticsearch.zip
@drush
drush / Crosstab for Ruby
Created March 8, 2010 21:15
A helper to convert model arrays into crosstab reports
# Crosstab module for ruby. This class allows you to iterate through an
# array of models (rows) and refactor the data to a crosstab format.
# This takes one of the columns and makes it your row-key, another column
# and makes it column-keys, then sums all cell values where these two
# keys interesect.
#
# Currently only a single column can be used for row-keys and column-keys
# but this may be expanded in the future with the addition of 'row grouping'