Skip to content

Instantly share code, notes, and snippets.

View shaiguitar's full-sized avatar
💭
We can pickle that

Shai Rosenfeld shaiguitar

💭
We can pickle that
View GitHub Profile
@shaiguitar
shaiguitar / gist:627d52ebc0c03af488477b5d636a8909
Created August 31, 2017 22:27
Using docker compose to mount current working directory dynamically into the container
# mount volume PWD on host to /app in container.
shai@lappy ~/tmp/example-working-docker-compose-environment-vars [master *] ± % cat docker-compose.yml
version: "3"
services:
some_server:
...
volumes:
- $PWD:/app
@shaiguitar
shaiguitar / gist:1032229
Created June 17, 2011 20:20
check processes with kill -0
usage()
{
echo "./$0 [--verbose]"
}
VERBOSE=0
if [ "$1" == "--verbose" ]; then
VERBOSE=1
fi
======================
I VI II V progression
======================
Assuming you can
1) Substitute the minor IV for a dominant IV and the minor II for a dominant II
2) Substitue any of the VI/II's (because of #1) or V for a tritone equivalent
So...Some notation/glossary for the below:
#!/bin/sh
### BEGIN INIT INFO
# Provides: odrive
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: odrive init script
# Description: odrive server startup sctipt.
@shaiguitar
shaiguitar / mycache.rb
Last active June 7, 2017 21:16
fog-core caching class
class MyCache
def self.all(resource_klass, connection, meth, args = nil)
cachemsg = "resource #{resource_klass} connection #{connection.class} for #{Fog::Cache.namespace_prefix}: M:#{meth} A:#{args}"
if MyCache.renew?
info("Renewing cache now. Cache is non existant or older than #{EXPIRE_TIME} seconds.")
Fog::Cache.expire_cache!(resource_klass, connection)
end
@shaiguitar
shaiguitar / cache-policies.md
Created June 7, 2017 15:51
Fog-core cache expire policy example.
  1. Record cache set/fetch time.
Fog::Cache.write_metadata({:last_refreshed => Time.now})
  1. Create some custom expirey method
      EXPIRE_TIME = (60 * 60 * 24) # day old cache.
 
@shaiguitar
shaiguitar / fog-example-cache.rb
Last active May 8, 2017 22:29
Fog caching example
require 'fog'
require 'fog/aws'
ec2 = Fog::Compute.new :provider => 'AWS', :region => 'us-east-1'
Fog::Cache.namespace_prefix = "benchmark-test"
begin
servers = Fog::Cache.load(Fog::Compute::AWS::Server, ec2)
puts "found cache."
@shaiguitar
shaiguitar / tail.rb
Last active July 22, 2016 09:22
tail in ruby
class Tail
class << self
def tail(path, n)
file = File.open(path, "r")
buffer_s = 512
line_count = 0
file.seek(0, IO::SEEK_END)
offset = file.pos # we start at the end
@shaiguitar
shaiguitar / git-find-original.sh
Last active December 30, 2015 18:29
Using git bisect to find the original commit that a piece of code/text entered the repo. Need this because many times you want to trace back when it was added, but when running a git show/blame you end up finding commits that just move that chuck around in the file/to different files etc.
# USAGE:
# reason for this is because sometimes you want to know when the originating code/comment/whatever was brought into the repo
# but you end up following a trace of lots of commits that just moved around the original chunk of code.
# this uses git bisect to trace back to the original commit that has this text in the repo.
# depends on ack, but you could easily change this to use `grep -r`
#
# $ git-find-original "some search string that you want to find the original commit that had this exact text"
match_arg="$@"
@shaiguitar
shaiguitar / manualcharencodings.rb
Last active December 28, 2015 09:18
manual char encodings
class StringHelper
def char_codes_for(str)
new_str = ""
str.each_char { |c| new_str << "&##{c.ord};" }
new_str
end
end