Skip to content

Instantly share code, notes, and snippets.

View SunDi3yansyah's full-sized avatar
Verified

Cahyadi Triyansyah SunDi3yansyah

Verified
View GitHub Profile
@SunDi3yansyah
SunDi3yansyah / .gitignore
Created August 26, 2016 11:12 — forked from WattsInABox/.gitignore
Generate Static HTML Website Using Ruby on Rails
# Ignore static version of the site (used to upload error pages to S3 for Heroku errors)
/out
@SunDi3yansyah
SunDi3yansyah / deploy_rails_app_on_ubuntu.md
Created September 10, 2016 20:46 — forked from he9lin/deploy_rails_app_on_ubuntu.md
Setup Rails application production environment on Ubuntu

Setup Rails application production environment on Ubuntu

Add deploy user

ssh root@YOURDOMAIN
adduser deploy
visudo # Add deploy ALL=(ALL) ALL

Install necessary libraries

#Simple Authentication with Bcrypt

This tutorial is for adding authentication to a vanilla Ruby on Rails app using Bcrypt and has_secure_password.

The steps below are based on Ryan Bates's approach from Railscast #250 Authentication from Scratch (revised).

You can see the final source code here: repo. I began with a stock rails app using rails new gif_vault

##Steps

@SunDi3yansyah
SunDi3yansyah / include-experiments.rb
Created September 15, 2016 11:55 — forked from themusicman/include-experiments.rb
Experiments with Module Includes in Ruby
# I created a generic Rails like ApplicationController so that you can just
# run this code via a command line prompt without the need for Rails
module Recorder
def self.included(base)
base.send(:before_filter, :some_method)
base.send(:after_filter, :another_method)
end
@SunDi3yansyah
SunDi3yansyah / gist:0716b5de630d99477e7be2e373db645e
Created September 18, 2016 20:07 — forked from dignoe/gist:2485272
Patch to get content_for working with action caching and fragment caching in Rails 3.1
module ActionController
class Metal
attr_internal :cached_content_for
end
module Caching
module Actions
def _save_fragment(name, options)
return unless caching_allowed?
@SunDi3yansyah
SunDi3yansyah / friendly_urls.markdown
Created September 24, 2016 11:51 — forked from agnellvj/friendly_urls.markdown
Friendly URLs in Rails

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@SunDi3yansyah
SunDi3yansyah / Encryption.php
Created September 28, 2016 15:41 — forked from niczak/gist:2501891
PHP Encrypt/Decrypt Class
<?php
class Encryption {
var $skey = "yourSecretKey"; // change this
public function safe_b64encode($string) {
$data = base64_encode($string);
$data = str_replace(array('+','/','='),array('-','_',''),$data);
return $data;
}
class AuthenticationsController < ApplicationController
# This is the callback method from OmniAuth's GitHub authentication.
# following http://railscasts.com/episodes/236-omniauth-part-2
def create
omniauth = request.env["omniauth.auth"]
authentication = Authentication.find_by_provider_and_uid(omniauth['provider'], omniauth['uid'])
if authentication
sign_in_and_redirect(:user, authentication.user)
end
@SunDi3yansyah
SunDi3yansyah / colors.xml
Created October 5, 2016 10:04
Material Design Color Palette Colors.xml Resource file for Android
<?xml version="1.0" encoding="utf-8"?>
<!--
Google Material Design Color Palette for Android http://www.google.com/design/spec/style/color.html#color-ui-color-palette
Spreadsheet used to create this reosurce - http://bit.ly/mdcolor_spreadsheet
Link to this colors.xml resource file - http://bit.ly/mdcolorsxml
Harshad Kale
https://github.com/kalehv
harshad.kale@gmail.com
@SunDi3yansyah
SunDi3yansyah / web-servers.md
Created October 12, 2016 20:06 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000