Skip to content

Instantly share code, notes, and snippets.

View kuntoaji's full-sized avatar
🎯
Focusing

KAK kuntoaji

🎯
Focusing
View GitHub Profile
// Tracking cursor position in real-time without JavaScript
// Demo: https://twitter.com/davywtf/status/1124146339259002881
package main
import (
"fmt"
"net/http"
"strings"
)
@kuntoaji
kuntoaji / progress_bar.rb
Created September 6, 2013 06:54
Simple progress bar script without Gem using Ruby.
#!/usr/bin/env ruby
progress = 'Progress ['
1000.times do |i|
# i is number from 0-999
j = i + 1
# add 1 percent every 10 times
if j % 10 == 0
@kuntoaji
kuntoaji / 1-activerecord.rb
Created November 21, 2018 03:40 — forked from janko/1-activerecord.rb
INSERTing 50,000 records into a database in ActiveRecord, Arel, SQL, activerecord-import and Sequel.
require "active_record"
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:")
ActiveRecord::Migration.class_eval do
create_table(:records) do |t|
t.string :column
end
end
data = 50_000.times.map { |i| Hash[column: "Column #{i}"] }
@kuntoaji
kuntoaji / encryptor.rb
Created October 19, 2018 02:50 — forked from aloucas/encryptor.rb
How to create dynamic attr_accessors (getters/setters) for encrypted attributes in a Ruby on Rails 5 Model.
# lib/encryptor.rb
# Module to dynamic encrypt attributes per model
module Encryptor
def has_encrypted_attributes(*attrs)
attrs.each do |attr|
# Define the dynamic getter
define_method(attr) do
self[attr].present? ? Encryptor.crypt.decrypt_and_verify(self[attr]) : self[attr]
end
# Define the dynamic setter
@kuntoaji
kuntoaji / hashtag_counter.rb
Created September 21, 2010 07:15
Ruby script to count a twitter hashtag and save the result and last_tweet_id to hashtag_counter_result.txt and last_tweet_id.tx
#!/usr/bin/env ruby
# Twitter Hashtag Counter
#
# Script to count a twitter hashtag and save the result and last_tweet_id to
# hashtag_counter_result.txt and last_tweet_id.txt
#
# Requirements: twitter gem.
# To install twitter gem: [sudo] gem install twitter
require 'rubygems'
activerecord-postgresql-4-2-4 sequel-postgresql-2-26-0 Benchmark
4.305316 0.307019 Eager Loading Query Per Association With 1-1 Records: 640 objects 22 times-No Transaction
4.281943 0.335119 Eager Loading Query Per Association With 1-1 Records: 640 objects 22 times-Transaction
1.229413 0.185485 Eager Loading Query Per Association With 1-32 Records: 1024 objects 22 times-No Transaction
1.226506 0.200746 Eager Loading Query Per Association With 1-32 Records: 1024 objects 22 times-Transaction
0.900579 0.146086 Eager Loading Query Per Association With 1-32-32 Records: 2048 objects 9 times-No Transaction
0.951023 0.146339 Eager Loading Query Per Association With 1-32-32 Records: 2048 objects 9 times-Transaction
4.925186 0.391609 Eager Loading Single Query With 1-1 Records: 640 objects 22 times-No Transaction
4.936297 0.420436 Eager Loading Single Query With 1-1 Records: 640 objects 22 times-Transaction
1.871573 0.417916 Eager Loading Single Query With 1-32 Records: 1024 objects 22 times-No Transaction
@kuntoaji
kuntoaji / main.js
Last active December 28, 2015 08:39
Javascript Alert For Unsaved Changes with Turbolinks and Jquery
// ...
change = function() {
$("form input, form textarea").change(function() {
$('a').click(function() {
confirm('Unsaved changes on the page. Are you sure?');
});
});
};
// ...
@kuntoaji
kuntoaji / README.md
Created October 13, 2013 05:40 — forked from nikcub/README.md
PATH="/opt/rubinius/1.2/gems/bin/:/opt/rubinius/1.2/bin:$PATH"
puts 'hellow world with gist client'