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:14986cecadee05e768e5
Created March 19, 2016 09:35 — forked from sulf/gist:1157909
Rails helper time_ago_in_words() and distance_of_time_in_words() translated into JavaScript
var distance_of_time_in_words, time_ago_in_words;
time_ago_in_words = function(from_time, include_seconds) {
if (include_seconds != null) {
include_seconds;
} else {
include_seconds = false;
};
return App.distance_of_time_in_words(from_time, Date.now(), include_seconds);
};
distance_of_time_in_words = function(from_time, to_time, include_seconds) {
require 'csv'
csv_text = File.read('...')
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
Model.create!(row.to_hash)
end
@kusakusakusa
kusakusakusa / js code
Created August 10, 2015 09:54
typeahead debugging
$('.typeahead').focus().typeahead('val', '').focus().typeahead('val', 'what ever value you want to test');
@kusakusakusa
kusakusakusa / assets path
Last active August 29, 2015 14:24
utility
Rails.application.config.assets.paths
if (typeof(some_variable) != 'undefined' && some_variable != null)
@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
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 {
CSV.open("myfile.csv", "w") do |csv|
csv << BusinessService.column_names
BusinessService.all.each do |m|
csv << m.attributes.values
end
end
$bootstrap-sass-asset-helper: false !default;
//
// Variables
// --------------------------------------------------
//== Colors
//
//## Gray and brand colors for use across Bootstrap.
grant all privileges on mydb.* to myuser@'%' identified by 'mypasswd';