Skip to content

Instantly share code, notes, and snippets.

@brycesch
brycesch / .bash_profile
Last active December 21, 2015 09:29 — forked from ehlertij/.bash_profile
# Set terminal window name to current git repo (and branch) or current directory
git-repo() {
git remote -v | grep '(fetch)' | grep -o "\/[a-z,A-Z,\_,\-]*\." | tail -1 | cut -c 2- | grep -o "[a-z,A-Z,\_,\-]*"
}
git-branch() {
git branch | grep \* | cut -c 3-
}
git-term() {
@brycesch
brycesch / filtered_search.rb
Last active December 22, 2015 20:48
general purpose search method to be used with the tire gem.
module FilteredSearch
extend ActiveSupport::Concern
module ClassMethods
def filtered_search(conditions, filters = {}, options = {})
return [] unless self.respond_to?(:tire) or conditions.nil?
FilteredSearch::CustomSearch.new(self, conditions, filters, options).search
end
end
@brycesch
brycesch / tire_bulk_import.rake
Created October 2, 2013 15:25
tire bulk importer
module Tire
module Tasks
module Import
def bulk_import_model(index, klass, options = {})
unless progress_bar(klass)
puts "[IMPORT] Importing '#{klass.to_s}'"
end
klass.scoped.find_in_batches(options) do |batch|
documents = batch.map(&:to_indexed_json)
progress_bar(klass).inc documents.size if progress_bar(klass)
/**
* Example of using an angular provider to build an api service.
* @author Jeremy Elbourn ([email protected])
*/
/** Namespace for the application. */
var app = {};
/******************************************************************************/
module_name = ARGV[0]
return "No module name given" unless module_name
files = Dir['/**/*.rb']
files.each do |f|
f = File.open(f, "r+")
lines = f.readlines
f.close
output = File.new(f, "w")
output.write "module #{module_name}\n"
def redirect_to(options = {}, response_status = {})
::Rails.logger.error("Redirected by #{caller(1).first rescue "unknown"}")
super(options, response_status)
end
@brycesch
brycesch / backup.sh
Last active June 1, 2017 21:04
create encrypted database backups
#!/bin/bash
# Do the following to create the pub.pem
# openssl rsa -in id_rsa -outform pem > id_rsa.pem
# openssl rsa -in id_rsa -pubout -outform pem > id_rsa.pub.pem
# gen rand key
openssl rand -base64 32 > key.bin
# timestamp for dump
@brycesch
brycesch / mysql_string_sanitizer.rb
Created September 6, 2017 16:30
String sanitizer for MySQL's default utf8 encoding - You can avoid needing to use this by switching to utf8mb4
class MysqlStringSanitizer
def self.sanitize(str)
str = str.force_encoding('utf-8').encode
clean_text = ""
# emoticons 1F601 - 1F64F
regex = /[\u{1f600}-\u{1f64f}]/
clean_text = str.gsub regex, ''
#dingbats 2702 - 27B0

Keybase proof

I hereby claim:

  • I am brycesch on github.
  • I am brycesch (https://keybase.io/brycesch) on keybase.
  • I have a public key ASDG86SfmH1zppp8yJMGD5ITxTJMuj5bFjTp_7j244zmDgo

To claim this, I am signing this object:

@brycesch
brycesch / tails_slack.sh
Last active April 8, 2021 17:40
tail file to webhook endpoint
#!/bin/bash
# chmod a+x tails.sh
# nohup ./tails.sh foobar.log webhook_url &
# use nohup if you want the cammand to persist after your session ends
#
# slack
tail -n0 -F "$1" | while read LINE; do
(echo "$LINE" | grep -e "$3") && curl -X POST --silent --data-urlencode \
"payload={\"text\": \"$(echo $LINE | sed "s/\"/'/g")\"}" "$2";
done