Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
if ['--help', '-h'].include?(ARGV[0]) || ARGV.size != 2
puts <<-EOT
Make web application shortcut
Usage: makewebapp <name> <URL>
EOT
exit
end
@emad-elsaid
emad-elsaid / 90-custom-kbd.conf
Last active May 1, 2017 16:34
X11 config file to convert capslock to control, and swap left control with left alt (mac style kbd) /etc/X11/xorg.conf.d/90-custom-kbd.conf
Section "InputClass"
Identifier "keyboard defaults"
MatchIsKeyboard "on"
Option "XKbOptions" "caps:lctrl,ctrl:swap_lalt_lctl"
EndSection
@emad-elsaid
emad-elsaid / string.rb
Created December 1, 2016 17:34
Convert string to hashtag, to use it simply drop this to a directory that is autoloaded like rails initializers and then "Hash tag".hashify it will produce "#Hash_tag"
class String
def hashify
"##{gsub(' ', '_')}"
end
end
def day_json
ids = popular_people.pluck(:id).join('.')
Rails.cache.fetch("pc/dj/#{ids}") do
render_to_string json: popular_people
end
end
We Found 52 Days, Yaaay:
2016-08-06
2016-08-13
2016-08-20
2016-08-27
2016-09-03
2016-09-10
2016-09-17
2016-09-24
2016-10-01
@emad-elsaid
emad-elsaid / stack.js
Last active July 29, 2016 17:14 — forked from khaled0fares/stack.js
Stack implementation in JS using class and constructor
'use strict'
let Stack = function(max){
if(typeof max != 'number' || max == NaN){
throw new Error(max + ' should be a number');
}
var Store = [],
top = 0,
empty = function() { return top === 0; },
class SimpleGit
def self.git(method_name, cmd = nil)
define_method(method_name) do |args|
if cmd
git("#{cmd} #{args}")
else
git("#{method_name} #{args}")
end
end
end
AllCops:
Exclude:
- 'vendor/**/*'
- 'db/schema.rb'
- 'db/migrate/**/*'
Metrics/LineLength:
Enabled: false
Style/Documentation:
Enabled: false
Style/StringLiterals:
# manages your string in terminal, each call to rendr will clear the old string
# and print the new one
# Extracted from
# https://github.com/arlimus/inquirer.rb/blob/master/lib/inquirer/utils/iohelper.rb
module Buffer
extend self
CARRIAGE_RETURN = "\r".freeze
LINE_UP = "\e[A".freeze
CLEAR_LINE = "\e[0K".freeze