Skip to content

Instantly share code, notes, and snippets.

View awesome's full-sized avatar

So Awesome Man awesome

View GitHub Profile
@awesome
awesome / gist:4dbb806528577fcd3525d2868f4cf1cd
Created September 5, 2018 17:21
python SimpleHTTPServer
#
# TEST SERVE WEBAPP
#
echo "hello world" > index.html
nohup python -m SimpleHTTPServer 80 &
@awesome
awesome / git-commit-fortune-usage.txt
Created August 29, 2018 01:19
Per Aaron's request for "git commit fortune" as in https://en.wikipedia.org/wiki/Fortune_(Unix)
Last login: Tue Aug 28 17:47:56 on ttys015
$ cat >> ~/.bashrc <<EOS
> function commit_fortune { curl -s "https://whatthecommit.com"| tr -d "\n\r" | perl -pe 's/.*<div id="content"><p>(.*)(?:<\/p><p class="permalink">).*/\1/';}
> function gcf { git commit -am "\$(commit_fortune)";}
> export -f commit_fortune
> export -f gcf
> EOS
$ source ~/.bashrc
$ echo $(commit_fortune)
I'm totally adding this to epic win. +300
@awesome
awesome / jq-json-to-associative-array-command-line-example.txt
Created August 22, 2018 20:10
jq parse JSON to bash4 associative array! "jq is like sed for JSON data" https://stedolan.github.io/jq/
admin@ip-172-31-90-86:~$ json=$(
cat <<- EOF
{
"foo": "baru-1",
"su": "baru-2",
"dive": "baru-3"
}
EOF
)
admin@ip-172-31-90-86:~$ echo $json
@awesome
awesome / gist:25afcea87d3d5355532d4811e1687590
Last active February 24, 2018 00:50
ruby check var for any case: 1) is an integer; 2) is an integer in string; or 3) is an integer in string in symbol
Last login: Fri Feb 23 16:16:47 on ttys004
dev-2:pumpone-rails dev$ irb
irb(main):001:0> def is_int?(arg)
irb(main):002:1> arg.to_s.to_i.to_s == arg.to_s
irb(main):003:1> end
=> :is_int?
irb(main):004:0> is_int? 1
=> true
irb(main):005:0> is_int? "1"
=> true
@awesome
awesome / gist:f1e7d2d3dfb01759b90dab4656e89579
Created February 22, 2018 02:00
holy shit! the capitalized underscore _ID is a column name! gonna use: `.underscore.camelcase` for an easy win; see: http://api.rubyonrails.org/classes/String.html#method-i-camelize
irb(main):016:0> "cool_id".camelcase
=> "CoolId"
irb(main):017:0> "cool_id".camelcase(:lower)
=> "coolId"
irb(main):018:0> "ServerID".underscore
=> "server_id"
irb(main):019:0> "ServerID".underscore.camelcase(:lower)
=> "serverId"
irb(main):020:0> "ServerID".camelcase(:lower)
=> "serverID"
@awesome
awesome / gist:da6f3b02932f7185e1d3b0bbf7a43b8a
Created February 21, 2018 21:55
rails camelize with :lower or nil in arg
irb(main):003:0> "cool_bro".camelize
=> "CoolBro"
irb(main):004:0> "cool_bro".camelize(:lower)
=> "coolBro"
irb(main):005:0> "cool_bro".camelize()
=> "CoolBro"
irb(main):006:0> "cool_bro".camelize(nil)
=> nil
irb(main):007:0> "cool_bro".camelize(x)
NameError: undefined local variable or method `x' for main:Object
@awesome
awesome / camelcase_with_lowercase_first_char.rb
Created September 29, 2017 21:40
"Ruby on Rails uncapitalize first letter" string camelcase with lowercase first char using ActiveSupport
require 'active_support/all'
# https://stackoverflow.com/questions/4474028/ruby-on-rails-uncapitalize-first-letter#13083654
"coolat_cat".camelize(:lower) # => "coolCat"
@awesome
awesome / how-to-get-a-list-of-all-registered-mime-types-in-rails.rb
Created August 2, 2017 20:14
How To Get A List of All Registered Mime Types in Rails
# via http://www.seanbehan.com/how-to-get-a-list-of-all-registered-mime-types-in-rails/
#
# How To Get A List of All Registered Mime Types in Rails
# When mime types are registered they are placed in a hash constant
# EXTENSION_LOOKUP in the module Mime. For reference, the file with
# the relevant code is in rails/action_pack/lib/action_dispatch/http/mime_type.rb available
# on Github at https://github.com/rails/rails/blob/master/actionpack/lib/action_dispatch/http/mime_type.rb
#
# You can check for existence of certain mime types with
Mime::Type.lookup_by_extension(:json)
@awesome
awesome / rails_4_2-config_for.rb
Created August 1, 2017 19:47
Easily load config files in Rails 4.2
# "Easily load config files
# OK, I might be biased. But having a built-in way to load config files is going to be awesome.
# config_for, new in Rails 4.2, works exactly like you’d expect:"
# http://www.justinweiss.com/articles/the-lesser-known-features-in-rails-4-dot-2/
Rails.application.config_for(:database)
# => {"adapter"=>"mysql2", "encoding"=>"utf8", "database"=>"development_db", "username"=>"root", "password"=>nil, "host"=>"localhost", "pool"=>5, "socket"=>"/tmp/mysql.sock"}
@awesome
awesome / print_amf.rb
Created June 28, 2017 04:32 — forked from jcward/print_amf.rb
RocketAMF can de/serialize AMF serialized byte streams, but it throws (at least, the 0.2.1 version from gem install throws) when it encounters an IExternalizable type in the byte steam. This patch allows it to parsed custom IExternalizable classes properly.
#!/usr/bin/env ruby
require 'rocketamf'
require 'stringio'
# Monkey patch for RocketAMF (0.2.1 gem) that handles IExrternalizable types
# in the input, storing their type as "__as3_type" parameter:
module RocketAMF
module Values #:nodoc:
class TypedHash