Skip to content

Instantly share code, notes, and snippets.

View hemju's full-sized avatar
😃
Work Work

Helmut M Juskewycz hemju

😃
Work Work
View GitHub Profile
@hemju
hemju / Capistrano-Deployment-Recipe.rb
Created August 5, 2011 13:11 — forked from mrrooijen/Capistrano-Deployment-Recipe.rb
a "base" Capistrano Rails Deployment Recipe. Use it to deploy your Rails application. It is also easily expandable. So feel free to grab this Recipe and add your own tasks/customization!
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
export JAVA_OPTS='-d32 -client -Xmx1g'
alias ls='ls -G'
alias ll='ls -l'
alias la='ls -la'
alias l='ls -l'
@hemju
hemju / optimize_images.rb
Created February 9, 2012 12:32 — forked from meleyal/optimize_images.rb
Simple png + jpg optimization script using optipng + jpegtran
#!/usr/bin/ruby
# Instructions
# - Install optipng + libjpeg (http://mxcl.github.com/homebrew/)
# - Put this file in a directory of images
# - Open in TextMate + run it (cmd+r)
# Config
@hemju
hemju / gist:2472073
Created April 23, 2012 16:25
translations
en:
html:
escaped: "<h2>lingohub</h2><p>can't wait to see it</p>"
raw: "<h2>lingohub</h2><p>can't wait to see it</p>"
html_safe: "<h2>lingohub</h2><p>can't wait to see it</p>"
ending_html: "<h2>lingohub</h2><p>can't wait to see it</p>"
@hemju
hemju / gist:2500433
Created April 26, 2012 15:37
three ways to use HTML in Rails translations
1: <%= t 'html.escaped' %> <!-- INCORRECT RESULT: &lt;h2&gt;lingohub&lt;/h2&gt;&lt;p&gt;can't wait to see it&lt;/p2&gt; -->
2: <%= raw t('html.raw') %> <!-- CORRECT RESULT: <h2>lingohub</h2><p>can't wait to see it</p> -->
3: <%= t('html.html_safe').html_safe %> <!-- CORRECT RESULT: <h2>lingohub</h2><p>can't wait to see it</p> -->
4: <%= t 'html.ending_html' %> <!-- CORRECT RESULT: <h2>lingohub</h2><p>can't wait to see it</p> -->
@hemju
hemju / stats.txt
Created May 9, 2012 09:39
rake stats of lingohub
+----------------------+-------+-------+---------+---------+-----+-------+
| Name | Lines | LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
| Controllers | 1729 | 1320 | 41 | 166 | 4 | 5 |
| Helpers | 604 | 442 | 1 | 72 | 72 | 4 |
| Models | 2133 | 1254 | 33 | 174 | 5 | 5 |
| Libraries | 4272 | 3101 | 100 | 373 | 3 | 6 |
| Model specs | 1988 | 1232 | 0 | 10 | 0 | 121 |
| View specs | 0 | 0 | 0 | 0 | 0 | 0 |
| Controller specs | 2656 | 2021 | 0 | 22 | 0 | 89 |
@hemju
hemju / word_char_count
Created July 24, 2013 11:01
Shows two queries to get the word count and character count of a string/text column in Postgres.
# Character count
select sum(length(YOUR_COLUMN)) from YOUR_TABLE;
# Word count
select sum(array_length(regexp_split_to_array(YOUR_COLUMN, '\s'),1)) from YOUR_TABLE;
#!/usr/bin/env ruby
require 'bundler'
require 'benchmark'
REGEXPS = [
/^no such file to load -- (.+)$/i,
/^Missing \w+ (?:file\s*)?([^\s]+.rb)$/i,
/^Missing API definition file in (.+)$/i,
/^cannot load such file -- (.+)$/i,
]
@hemju
hemju / PostgreSQL Index Check
Created June 3, 2014 13:48
Prints out all indices together with stats about size, reads, ....
SELECT
t.tablename,
indexname,
c.reltuples AS num_rows,
pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size,
pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size,
CASE WHEN indisunique THEN 'Y'
ELSE 'N'
END AS UNIQUE,
idx_scan AS number_of_scans,
@hemju
hemju / gist:94713cacdbac9d08071d
Last active August 29, 2015 14:03
Blog: Dynamic Ruby Example Example
def import_file_data(file_path, content, import_type, strategy_name, additional_attributes = {}, options = {})
# probably file_path is a String and the result file_name as well
file_name = File.basename(file_path)
# no idea what tempfile is, a string?
tempfile = write_to_temp_file(content, file_name)
uploaded_file = OpenStruct.new(:original_filename => file_name, :tempfile => tempfile)
# Is this now an instance of ResourceImport or a result of a resource import?
resource_import = ResourceImport.import!(user, project, uploaded_file, file_path, import_type, strategy_name, additional_attributes)