Skip to content

Instantly share code, notes, and snippets.

@mbchoa
mbchoa / recentposts.html.erb
Last active August 29, 2015 13:56
"Recent Posts" HTML+ERB gist
<h2>RECENT POSTS</h2>
<ol>
<% blog.articles[0...10].each do |article| %>
<li><%= link_to article.title, article %> <span><%= article.date.strftime('%b %e') %></span></li>
<% end %>
</ol>
@mbchoa
mbchoa / archive.html.erb
Last active August 29, 2015 13:56
"Archive" HTML+ERB gist
<h2>ARCHIVE</h2>
<ol>
<% blog.articles.group_by {|a| a.date.year }.each do |year, articles| %>
<li><%= link_to year, blog_year_path(year) %></li>
<% end %>
</ol>
@mbchoa
mbchoa / tags.html.erb
Last active August 29, 2015 13:56
"Tags" layout.erb
<h2>TAGS</h2>
<ol>
<% blog.tags.each do |tag, articles| %>
<li><%= link_to tag, tag_path(tag) %> (<%= articles.size %>)</a></li>
<% end %>
</ol>
@mbchoa
mbchoa / gist:f1ddff8dddbe5a1ef5c7
Created May 17, 2014 04:06
Installing Sublime Text 3 via Linux Package Manager (apt-get)
sudo add-apt-repository ppa:webupd8team/sublime-text-3
sudo apt-get update
sudo apt-get install sublime-text-installer
@mbchoa
mbchoa / Iterate Java Map with 'For' Loop
Created March 6, 2015 18:55
Iterating through a Java Map
for (Map.Entry<String, String> entry : map.entrySet())
{
System.out.println(entry.getKey() + "/" + entry.getValue());
}
@mbchoa
mbchoa / BitwiseAbsoluteValue
Created March 11, 2015 15:12
Determine integer absolute value using bitwise operations
public static int abs(int value){
int mask = value>>31;
return (value ^ mask) - mask;
}
@mbchoa
mbchoa / Radix Sort 1
Created March 23, 2015 02:21
Java implementation of Radix Sort assuming base 10
private static int[] radixSort(int[] unsortedArr, int digits){
for(int i = 1; i <= digits; ++i){
unsortedArr = countSort(unsortedArr, 10, (int)Math.pow(10, i));
}
return unsortedArr;
}
private static int[] countSort(int[] unsortedArr, int base, int digit){
int[] keyArray = new int[base];
@mbchoa
mbchoa / Integer Length "For" Loop
Created March 26, 2015 00:03
Find the number of digits in an integer
for(long long int temp = number; temp >= 1;)
{
temp/=10;
decimalPlaces++;
}
@mbchoa
mbchoa / Unix Recursive Remove
Created April 7, 2015 13:37
Recursively force remove files and directories in current directory and all sub-directories in Unix
find . -name "NAME" -print0 | xargs -0 rm -rf
@mbchoa
mbchoa / rand_helper.py
Created November 13, 2015 15:17
Python module which will contain various functions for randomly generating values.
import random
import string
def rand_string(length):
return ''.join(random.choice(string.printable) for x in range(length))
print rand_string(64)