Skip to content

Instantly share code, notes, and snippets.

View kusakusakusa's full-sized avatar
💭
Digital nomad | RubyOnRails | AWS

Victor Leong kusakusakusa

💭
Digital nomad | RubyOnRails | AWS
View GitHub Profile
@kusakusakusa
kusakusakusa / gist:d7bae9cd3fd6b468ac04
Last active August 29, 2015 14:05
kill already running rails server
lsof -wni tcp:3000
kill -9 <PID>
# in ApplicationHelper.rb
def flash_class(level)
case level
when :notice then "alert alert-info"
when :success then "alert alert-success"
when :error then "alert alert-error"
when :alert then "alert alert-block"
else "alert #{level}
end
end
@kusakusakusa
kusakusakusa / gitignore
Last active August 29, 2015 14:06
rails new app essential setup
# Ignore bundler config.
/.bundle
# Ignore the default SQLite database.
/db/*.sqlite3
/db/*.sqlite3-journal
# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
@kusakusakusa
kusakusakusa / command line
Last active August 29, 2015 14:12
create .ruby-version and .ruby-gemset for project
rvm --create --ruby-version 2.2.1@victor
grant all privileges on mydb.* to myuser@'%' identified by 'mypasswd';
$bootstrap-sass-asset-helper: false !default;
//
// Variables
// --------------------------------------------------
//== Colors
//
//## Gray and brand colors for use across Bootstrap.
CSV.open("myfile.csv", "w") do |csv|
csv << BusinessService.column_names
BusinessService.all.each do |m|
csv << m.attributes.values
end
end
func deviceRemainingFreeSpaceInBytes() -> Int64? {
let documentDirectoryPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let systemAttributes = NSFileManager.defaultManager().attributesOfFileSystemForPath(documentDirectoryPath.last as String, error: nil)
let freeSize = (systemAttributes?[NSFileSystemFreeSize] as? NSNumber)?.longLongValue
return freeSize
}
if let bytes = deviceRemainingFreeSpaceInBytes() {
println("free space: \(bytes)")
} else {
@kusakusakusa
kusakusakusa / to_csv
Created June 18, 2015 03:31
rails console
require 'csv'
file = "#{Rails.root}/data.csv"
schools = School.where(state_code: 'CO').order('name ASC')
CSV.open( file, 'w' ) do |writer|
schools.each do |s|
writer << [s.name, s.zipcode, s.id]
end
if (typeof(some_variable) != 'undefined' && some_variable != null)