Skip to content

Instantly share code, notes, and snippets.

View imouaddine's full-sized avatar

Imad Mouaddine imouaddine

  • Measured
  • Casablanca
View GitHub Profile
@imouaddine
imouaddine / gist:9104270
Created February 20, 2014 00:06
Fixed template.php of current
<?php
$style = theme_get_setting('style');
switch ($style) {
case 1:
drupal_add_css(drupal_get_path('theme', 'current') . '/css/style1.css', array('group' => CSS_THEME, 'weight' => 100, 'type' => 'file'));
break;
case 2:
drupal_add_css(drupal_get_path('theme', 'current') . '/css/style2.css', array('group' => CSS_THEME, 'weight' => 100, 'type' => 'file'));
@imouaddine
imouaddine / Largest Sum Contiguous Subarray
Last active August 29, 2015 14:08
Largest Sum Contiguous Subarray
def max_subarray(a)
max = - Float::INFINITY
max_at = []
sum = 0
sum_at = []
a.each_with_index do |e, i|
def isomorphic(a,b)
if a.length == 0 && b.length == 0
true
elsif a.length != b.length
false
else
a_stru = b_stru = Hash.new{|hash, key| hash[key] =[] }
b_stru = Hash.new{|hash, key| hash[key] =[] }
def product_max(a)
max_so_far = 1
min_so_far = 1
max = 1
a.each do |i|
@imouaddine
imouaddine / gist:8284d641984307280363
Created November 6, 2014 19:49
Minimum distance between two words in a string
def distance(a,b)
words = "I am a good girl".split(/\W+/)
a_found = false
b_found = false
prev = nil
words.each_with_index do |word, index|
if word == a
@imouaddine
imouaddine / gist:c870be92c30a80535aff
Created November 8, 2014 16:15
Merge two linked list
class LinkedList
attr_accessor :head, :tail
class Node
attr_accessor :previous, :next, :value
def initialize(value)
@value = value
end
end
def compress_length(a)
if a.length < 3
return a
end
result = ""
count = 1
a.chars.each_with_index do |c, index|
if c == a[index+1]
def rotate_matrix(a, length)
(0).upto(length -1) do |i|
(i+1).upto(length -1) do |j|
a[i][j], a[j][i] = a[j][i], a[i][j]
end
end
a
end
@imouaddine
imouaddine / Remove duplicates of linked list
Created November 10, 2014 22:34
o(n2) without any temporary buffer
def remove_duplicates
unless head && head.next
return self
end
current = head
while(current)
runner = current.next
_previous = current
while(runner)
if runner.value == current.value
@imouaddine
imouaddine / Partition Linked List
Created November 12, 2014 14:50
Partition Linked List
class LinkedList
attr_accessor :head, :tail
class Node
attr_accessor :previous, :next, :value
def initialize(value)
@value = value
end
end