Skip to content

Instantly share code, notes, and snippets.

@yudapc
yudapc / php
Last active July 29, 2016 07:41
fizzbuzz code
<?php
for($i = 1; $i <= 100; $i++) {
$val = $i;
if($i % 3 == 0) $val = "Fizz";
if($i % 5 == 0) $val = "Buzz";
if($i % 3 == 0 && $i % 5 == 0) $val = "FizzBuzz";
echo $val."\n";
}
@yudapc
yudapc / Add User for specific database
Last active August 29, 2015 14:19
Mysql Ubuntu 14.04
CREATE USER 'userbaru'@'localhost' IDENTIFIED BY 'password_disini';
GRANT ALL PRIVILEGES ON namadatabase.* To 'userbaru'@'localhost' IDENTIFIED BY 'password_disini';
change password user:
use mysql;
update user set password=PASSWORD('your_new_password') where User='root';
@yudapc
yudapc / boxgue.conf
Created November 13, 2015 16:25
Apache2 OS X
# /etc/apache2/vhost
<VirtualHost *:80>
ServerName local.boxgue.com
ServerAlias local.boxgue.com
DocumentRoot "/Users/cogati/Sites/boxgue"
ErrorLog "/private/var/log/apache2/boxgue.com-error_log"
CustomLog "/private/var/log/apache2/boxgue.com-access_log" common
ServerAdmin [email protected]
</VirtualHost>
@yudapc
yudapc / example hash to object
Last active November 18, 2015 02:34
Ruby - Hash to Object
class Hashit
def initialize(hash)
hash.each do |k,v|
self.instance_variable_set("@#{k}", v.is_a?(Hash) ? Hashit.new(v) : v)
self.class.send(:define_method, k, proc{self.instance_variable_get("@#{k}")})
self.class.send(:define_method, "#{k}=", proc{|v| self.instance_variable_set("@#{k}", v)})
end
end
end
@yudapc
yudapc / Cheat Rspec.rb
Last active October 31, 2016 10:35
RSpec
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
@yudapc
yudapc / Doorkeeper
Last active September 16, 2016 09:56
OAuth2 with rails / ruby
location: `config/initializers/doorkeeper.rb`:
```
resource_owner_authenticator do
current_user || begin
session[:user_return_to] = request.fullpath
redirect_to new_user_session_url
end
end
```
[user]
name = Yuda Cogati
email = [email protected]
[alias]
# checkout a branch
co = "checkout"
# checkout a new branch
cob = "checkout -b"
# adds all changed files
@yudapc
yudapc / Ubuntu 16.04
Last active August 14, 2016 08:04
prepare
sudo apt-get install checkinstall build-essential automake autoconf libtool pkg-config libcurl4-openssl-dev intltool libxml2-dev libgtk2.0-dev libnotify-dev libglib2.0-dev libevent-dev
sudo apt-get install libmagickwand-dev
sudo apt-get install ruby-dev
sudo apt-get install imagemagick
@yudapc
yudapc / A Rails Trick
Last active August 30, 2017 14:45
Rails console
---------------------------
Pengganti .find or .find_by
---------------------------
categories = outlet.categories
categories.select{|c| c[:id] == item[:category_id]}.first
---------------------------
Penganti check value hash
---------------------------
@yudapc
yudapc / gist:4fa9eb551826ea35ea0fab109387b8d3
Created September 18, 2016 09:17 — forked from adamstac/gist:7462202
Install and configure Sendmail on Ubuntu

Install and configure Sendmail on Ubuntu

This should help you get Sendmail installed with basic configuration on Ubuntu.

  1. If sendmail isn't installed, install it: sudo apt-get install sendmail
  2. Configure /etc/hosts file: nano /etc/hosts
  3. Make sure the line looks like this: 127.0.0.1 localhost yourhostname
  4. Run Sendmail's config and answer 'Y' to everything: sudo sendmailconfig
  5. Restart apache sudo service apache2 restart