Skip to content

Instantly share code, notes, and snippets.

View hnq90's full-sized avatar
🎯
Focusing

Huy Nguyen Quang hnq90

🎯
Focusing
View GitHub Profile
@hnq90
hnq90 / filterable.rb
Last active August 29, 2015 14:27 — forked from justinweiss/filterable.rb
Filterable
# Call scopes directly from your URL params:
#
# @products = Product.filter(params.slice(:status, :location, :starts_with))
module Filterable
extend ActiveSupport::Concern
module ClassMethods
# Call the class methods with the same name as the keys in <tt>filtering_params</tt>
# with their associated values. Most useful for calling named scopes from

The Haml/Slim view generators were removed from Devise 1.2. Here is a tutorial how to create Haml/Slim views with Devise 1.2 or later.

Summary

rails generate devise:views

gem install html2haml
for file in app/views/devise/**/*.erb; do html2haml -e $file ${file%erb}haml && rm $file; done
def is_single_riffle_recursive_optimized(half1, half2, shuffled_deck, shuffled_deck_index=0, half1_index=0, half2_index=0):
# base case we've hit the end of shuffled_deck:
if shuffled_deck_index + 1 > len(shuffled_deck):
return True
# if we still have cards in half1
# and the "top" card in half1 is the same
# as the top card in shuffled_deck
if (not half1_index + 1 > len(half1)) and \
half1[half1_index] == shuffled_deck[shuffled_deck_index]:
def get_random(floor, ceiling):
return random.randrange(floor, ceiling + 1)
def shuffle(the_array):
# if it's 1 or 0 items, just return
if len(the_array) <= 1:
return the_array
last_index_in_the_array = len(the_array) - 1
def get_random(floor, ceiling):
return random.randrange(floor, ceiling + 1)
def naive_shuffle(the_array):
# for each index in the array
for first_index in xrange(0,len(the_array)-1):
# grab a random other index
second_index = get_random(0, len(the_array)-1)
@hnq90
hnq90 / _README.md
Last active August 29, 2015 14:25 — forked from remy/_README.md

raf.js

A simple script with a few niceties that allows for multiple requestAnimationFrame calls, and FPS pinning.

How it works

The script polyfills rAF if required, then overloads requestAnimationFrame and cancelAnimationFrame with a process that allows multiple frames to be queued up for rAF to run.

This is useful if there are multiple animations running on the page, you want all the callbacks to happen at once, and not on multiple rAF calls. This script is meant as a drop-in solution to that problem.

@hnq90
hnq90 / techlooper_contest.rb
Created July 1, 2015 11:40
Techlooper Contest - Decode Braille
#!/usr/bin/env ruby
# Reference: http://www.loc.gov/nls/reference/braille/card.html
# Contest: http://techlooper.com/#/contest
# HuyNQ
braille_alphabet= [
'0.....',
'0.0...',
'00....',
'00.0..',
# This is a short cut method to set the start anchor position
# If you need finer granularity in positioning use
# graphic_frame.anchor.from.colOff / rowOff
# @param [Integer] x The column
# @param [Integer] y The row
# @return [Marker]
def start_at(x, y=0)
x, y = *parse_coord_args(x, y)
@graphic_frame.anchor.from.col = x
@graphic_frame.anchor.from.row = y
# http://vietnamnet.vn/vn/giao-duc/238840/bao-anh-cong-bo-dap-an-bai-toan-lop-3-cua-viet-nam.html
Array(1..9).permutation {|n| p n if n[0]+13*n[1]/n[2]+n[3]+12*n[4]-n[5]-11+n[6]*n[7]/n[8]-10 == 66}
@hnq90
hnq90 / 01-intro.md
Last active August 29, 2015 14:23 — forked from dwayne/01-intro.md

Introduction

Author: Ari Lerner.

AngularJS offers a single framework that can be used to build dynamic, client-centric applications. It provides:

  • Module support
  • DOM manipulation
  • Animations
  • Templating