Skip to content

Instantly share code, notes, and snippets.

View emdeeeks's full-sized avatar

Gareth Griffiths emdeeeks

View GitHub Profile
@dimroc
dimroc / analytic.rb
Last active April 23, 2023 20:52
Server side mixpanel analytics implementation in ruby. There are other simple devise controllers that are overridden omitted from gist.
# http://blog.mixcel.io/10-ways-to-get-mixpanel-right-the-first-time-yHNlbz-wbcZz7E7PWMXvRg
class Analytic
module Mixpanelable
extend ActiveSupport::Concern
private
def mp_track(event_name, options = {})
mp_track_for_user(current_user, event_name, options)
end
@ayosec
ayosec / x11-change-opacity.sh
Created September 7, 2015 18:49
X11: Set Opacity
window=0x00.....
opacity=30 # Something between 0 and 100
xprop -id $window \
-f _NET_WM_WINDOW_OPACITY 32c \
-set _NET_WM_WINDOW_OPACITY $(($opacity*0xffffffff/100))
@valikos
valikos / variable.rb
Created July 21, 2015 08:07
Variables in ruby
class A
@foo = :foo
@@bar = :bar
attr_reader :foo
def foo
@foo = :bla
end
@jmlrt
jmlrt / dotfile.rake
Last active July 22, 2023 07:44
Dotfiles Rakefile
require 'date'
date = DateTime.now.strftime("%Y%m%d%H%M")
$homedir = Dir.home
$dotfiles = [ '.bash_profile', '.bashrc', '.gitconfig', '.kshrc', '.profile', '.tmux.conf', '.vimrc' ]
desc "backup dotfiles"
task :backup do |t|
backupdir = File.join($homedir,"/",t.name)
backupfile = "dotfiles-home.#{date}.tar"
@egwspiti
egwspiti / get_pos.rb
Last active October 6, 2024 08:06
pure ruby get terminal cursor position
require 'io/console'
class Cursor
class << self
def pos
res = ''
$stdin.raw do |stdin|
$stdout << "\e[6n"
$stdout.flush
while (c = stdin.getc) != 'R'
@Slike9
Slike9 / rails_model_form
Last active July 12, 2023 00:15
rails ModelForm
module ModelForm
extend ActiveSupport::Concern
included do
class_attribute :model_class
self.model_class = self.superclass
end
module ClassMethods
def model_name
@novohispano
novohispano / application_helper.rb
Created February 18, 2015 11:45
Caching in Rails
module ApplicationHelper
def cache_key_for(model)
prefix = model.to_s.downcase.pluralize
count = model.count
max_updated_at = model.maximum(:updated_at).try(:utc).try(:to_s, :number)
"#{prefix}/all-#{count}-#{max_updated_at}"
end
end
@usmanbashir
usmanbashir / shirt
Created January 19, 2015 15:01
A Unix Shell In Ruby
#!/usr/bin/env ruby
require 'shellwords'
def main
loop do
$stdout.print ENV['PROMPT']
line = $stdin.gets
if line
line.strip!
@kiasaki
kiasaki / uid.rb
Created September 21, 2014 00:48
Rails UID Concern
module Uid
extend ActiveSupport::Concern
included do
before_create :generate_uid
end
def to_param
self.uid
end
@vladimir-e
vladimir-e / example_controller.rb
Created August 11, 2014 09:00
Orderable concern rails 3
class Admin::SizesController < Admin::AdminController
include OrderableController
end