Skip to content

Instantly share code, notes, and snippets.

View agungyuliaji's full-sized avatar
🏠
Working from home

Agung Yuliaji agungyuliaji

🏠
Working from home
View GitHub Profile
@agungyuliaji
agungyuliaji / postgres_change_column_string_to_integer.rb
Last active December 20, 2015 10:49
Postgres change column string to integer
class ChangeColumnOnMovementShipmentDvcaAndDvcu < ActiveRecord::Migration
def change
rename_column :movement_shipments, :dvca, :dvca_s
rename_column :movement_shipments, :dvcu, :dvcu_s
add_column :movement_shipments, :dvca, :decimal, default: 0
add_column :movement_shipments, :dvcu, :decimal, default: 0
MovementShipment.reset_column_information
MovementShipment.find_each { |c| c.update_attributes({
@agungyuliaji
agungyuliaji / file_browser_live_image_preview.html
Last active December 18, 2015 11:59
Live image preview for file browser
<h1>Sample#preview_image_file_browser</h1>
<input id="one_image" name="one_image" type="file">
<div id="preview_container"></div>
<script type="text/javascript">
var setPreviewImage = function(file){
var reader = new FileReader(),
newImage = new Image();
@agungyuliaji
agungyuliaji / check_array_if_all_element_is_0.rb
Created March 6, 2013 08:03
Check array if all element is 0
[0,0,0,0,0,0].all? {|a| a.zero? } # => true
[0,1,0,0,0,0].all? {|a| a.zero? } # => false
@agungyuliaji
agungyuliaji / validate_text_field_with_some_words.html
Last active December 13, 2015 18:59
Validate Text Field with some words
<!DOCTYPE html>
<html>
<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
<body>
<input id="test">
@agungyuliaji
agungyuliaji / get_response_code_on_rescue_from.rb
Created February 13, 2013 09:17
Get Response Code on rescue_from
# code snippet is taken from app/controllers/application_controller.rb
rescue_from Exception do |exc|
@response = Rack::Utils.status_code(ActionDispatch::ShowExceptions.rescue_responses[exc.class.name]).to_s
case @response
when "401", "404", "422"
@text = "You may have mistyped the address or the page may have moved."
when "500"
@text = "There was an internal error (failure). Please wait a few minutes and try again."
brew install ntfs-3g
sudo mv /sbin/mount_ntfs /sbin/mount_ntfs.orig
sudo ln -s /usr/local/Cellar/ntfs-3g/2014.2.15/sbin/mount_ntfs /sbin/mount_ntfs
The new osxfuse file system bundle needs to be installed by the root user:
sudo /bin/cp -RfX /usr/local/opt/osxfuse/Library/Filesystems/osxfusefs.fs /Library/Filesystems/
sudo chmod +s /Library/Filesystems/osxfusefs.fs/Support/load_osxfusefs
class ProductImageUploader < CarrierWave::Uploader::Base
def store_dir
"product"
end
def filename
ext = File.extname(original_filename) if original_filename
"#{model.name.parameterize}#{ext}"
end
@agungyuliaji
agungyuliaji / include_jquery_from_console.js
Created May 5, 2014 13:16
Include jQuery in the JavaScript Console
var jq = document.createElement('script');
jq.src = "http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
document.getElementsByTagName('head')[0].appendChild(jq);
// ... give time for script to load, then type.
jQuery.noConflict();
@agungyuliaji
agungyuliaji / mymodel.rb
Created May 2, 2014 12:07 — forked from aliang/mymodel.rb
Render from model in Rails 3
# yes, sometimes you need to do this. you get pilloried in a forum if you
# ask about it, though!
# this code taken from
# http://wholemeal.co.nz/blog/2011/04/05/rendering-from-a-model-in-rails-3/
class MyModel < ActiveRecord::Base
# Use the my_models/_my_model.txt.erb view to render this object as a string
def to_s
ActionView::Base.new(Rails.configuration.paths.app.views.first).render(