Skip to content

Instantly share code, notes, and snippets.

View oelmekki's full-sized avatar

kik oelmekki

View GitHub Profile
class App.Url
parser_regexp: /^(.*:\/\/)([^:\/]+)(:[^\/]+)?(.*?)(\?.*?)?(#.*)?$/
constructor: ( initial ) ->
initial.replace( @parser_regexp, ( match, @_protocol, @_domain, @_port, @_path, @_params, @_anchor ) => )
@protocol = if @_protocol then @_protocol.replace( /:\/\//, '' ) else ''
@domain = @_domain or ''
@port = if @_port then @_port.replace( /:/, '' ) else ''
@path = @_path or ''
@params = if @_params then @_params.replace( /^\?/, '' ) else ''
@oelmekki
oelmekki / article.md
Last active July 30, 2016 16:13
Reduced row echelon with rows expansion

Reduced row echelon with rows expansion

Learning about matrices on KhanAcademy, I came to a great video from Sal Khan explaining how to use matrices to solve equations. Thanks!

What occured to me while watching the demonstration was that it seems inefficient to reuse the same rows to drop results, because we lose potentially valuable previous rows, which could help us in further steps. My initial thought was : "we could probably make this more easy/efficient by create new rows for the results", so I decided to play with that idea.

Initial demonstration

Here is the equation system Sal started from:

@oelmekki
oelmekki / sentences_distance.sql
Last active July 26, 2016 15:28
Order sentences by similarities in postgres
-- $ createdb test
-- $ psql test
CREATE TABLE sentences( words varchar(255)[] );
INSERT INTO sentences VALUES( ARRAY['hello', 'world', 'how', 'are', 'you', 'doing', 'today'] );
INSERT INTO sentences VALUES( ARRAY['how', 'are', 'you', 'doing', 'today', 'Jim'] );
INSERT INTO sentences VALUES( ARRAY['Maybe', 'this', 'sentence', 'will', 'not', 'be', 'as', 'close'] );
-- extract as function for less typing

Why progressive enhancement matters

A recent story on Hacker News pop up and informed us that progressive enhancement is dead.

The main point for this article was that it's kind of ridiculous in 2013 to build a whole app having in mind that user may deactivate javascript. I can't agree more with that, as did most HN commenters.

function prompt_extensions {
if [[ "$?" != "0" ]]; then
_prompt_status="$(echo -en '\033[41m\033[33m \033[00m')"
fi
echo -e "\n"
echo -n $_prompt_status
unset _prompt_status
}
" File: replace_quotes.vim
" Author: Olivier El Mekki
" Email: olivier@el-mekki.com
" Description: quick replace of quotes you're inside
" Usage:
" :QuotesToDouble - replaces outer single quotes with double quotes
" :QuotesToSingle - replaces outer double quotes with single quotes
if exists('replace_quotes_plugin')
finish
class Object
# Display an object methods list with their source location.
#
# @param [Regexp] method_pattern grep method name
# @param [Regexp] file_pattern grep file name
def located_methods( method_pattern = nil, file_pattern = nil )
list = ( method_pattern ? methods.grep( method_pattern ) : methods ).sort.map do |name|
location = method( name ).source_location
location = "#{location.first} line #{location.second}" if location
[ name.to_s.colorize( :yellow ), location ]
module ApplicationHelper
# Format errors for display.
# Resource may be a model or an handler - just anything including ActiveModel::Validations
#
# @param [Object] resource the source of errors
# @return [String] the error html
def error_messages_for_handler( resource )
message = <<-EOS
<div id="error_explanation">
<ul>
# A context encapsulate behavior for altering database
# in a specific situation.
#
# It is most notably responsible for validations and
# parameters filtering. You may also add in there all the
# custom logic that should be trigger on a specific context,
# like sending mails or updating other resources.
#
#
# # The problem
class I18nGenerator < Rails::Generators::NamedBase
def create_files
I18n.available_locales.each do |locale|
create_locale_file( locale )
end
end
private
def namespaces