Skip to content

Instantly share code, notes, and snippets.

@ptzn
ptzn / karabiner.json
Created Jan 2, 2018
remapping cmd+space to right command using karabiner-elements
View karabiner.json
// REMAPPING CMD+SPACE TO RIGHT COMMAND USING https://github.com/tekezo/Karabiner-Elements
// Put following code into rules section into ~/.config/karabiner/karabiner.json file
// "profiles": [
// ...
"rules": [
{
"description": "RightCommand to Switch Input Source",
"manipulators": [
{
"conditions": [
View rm-tm-backups.sh
#!/bin/sh
# Remove backups older than a given days
TM_PATH=/Volumes/stuff0/Backups.backupdb/zeus
DAYS=60
sudo find "${TM_PATH}" -maxdepth 1 -mtime +${DAYS} -type d -execdir tmutil delete '{}' \;
exit 0
View alias.zsh
# usage:
# say hello; notify #=> "Done" message will be sent on success and "Ooops" on error
# say hello; notify "in far far away galaxy" #=> "in far far away galaxy" message will be sent on success and "Ooops" on error
notify() {
local exit_code=$?
local api_key="PUT_API_KEY"
local chat_id="PUT_CHAT_ID_HERE"
@ptzn
ptzn / report
Last active Dec 24, 2015
Generate HTML report from CSV file generated by TimeTracker.app
View report
#!/usr/bin/env ruby
#
# Generate HTML report from CSV generated by TimeTracker.app
# Options:
# -i, --input - path to csv file
# -s, --start-time - report start time
# -e, --end-time - report end time (today by default)
# -p, --project - project name to include into report (all by default)
# -d, --delimiter - CSV delimiter ("," by default)
# -o, --out - directory to write report
View gist:6268361
constraints(OwnDomain) do
match # ...
resources #...
end
class OwnDomain
def self.matches?(request)
request.subdomain.present? && request.subdomain != "www" && request.host !~ /localhost|\.local|hostname\.com/
end
end
View bm.rb
search_for = '46846'
value = '00000'
stats = []
search_for.size.times do |index|
stats[index] ||= []
10.times do |digit|
View google_bot_aware.rb
# This Rack middleware helps solving the issue with some Rails versions which do not accept
# a '*/*;q=0.6' and their variants 'Accept' request header. This header is particularly used
# by Google Bot, and if Rails doesn't like it, it will return a 500 or 406 error to Google Bot,
# which is not the best way to get your pages indexed.
#
# References:
# - http://stackoverflow.com/questions/8881756/googlebot-receiving-missing-template-error-for-an-existing-template
# - https://github.com/rails/rails/issues/4127
#
class GoogleBotAware
@ptzn
ptzn / formatted_date_attribute.rb
Created Jun 3, 2011 — forked from skojin/formatted_date_attribute.rb
virtual formatted date attribute
View formatted_date_attribute.rb
module FormattedDateAttributes
# Define virtual formatted date attribute
#
# formatted_date_attribute(:start_at, :end_at, :format => :default)
# formatted_date_attribute(:start_at, :end_at, :format => '%d/%m/%y')
#
# format parameter can be a symbol from config/initializers/date_time_formats.rb or any
# string format that will work with Date#strftime and DateTime.strptime methods
def formatted_date_attributes(*args)
options = { :format => :default }.merge(args.extract_options!)
View .zshrc
setopt autocd
setopt CORRECT
autoload -U compinit
compinit
#zmodload zsh/complist
zstyle ':completion:*' menu yes select
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:processes' command 'ps -xuf'
View gist:876905
def gimme_class
eval %{
class MethodClass
def where_am_i?
puts "in method!"
end
end
}
obj = MethodClass.new