Skip to content

Instantly share code, notes, and snippets.

View mahdavipanah's full-sized avatar
💻
Wired in

Hamidreza Mahdavipanah mahdavipanah

💻
Wired in
View GitHub Profile
@mahdavipanah
mahdavipanah / fixbootsplash.sh
Last active April 23, 2016 20:36
Ubuntu After Installation Todos
#! /bin/bash
# Fix Ubuntu Plymouth Boot Splash
# if entry exists for $vt_handoff use sed to search and replace
# write to tmp file - move to original
checkVT=$(grep -c "\$vt_handoff" /boot/grub/grub.cfg)
if [ ! "$checkVT" -eq "0" ]
then
echo "> Found vt_handoff removing ..."
@mahdavipanah
mahdavipanah / simple-pagination.js
Last active July 23, 2016 16:42 — forked from kottenator/simple-pagination.js
Simple pagination algorithm
// Implementation in ES6
function pagination(c, m, delta) {
var current = c,
last = m,
left = current - delta,
right = current + delta,
range = [],
rangeWithDots = [],
l;
@mahdavipanah
mahdavipanah / pylearn-sololearn.md
Last active August 28, 2016 13:15
My notes in learning python via sololearn.com

In except blocks, the raise statement can be used without arguments to re-raise whatever exception occurred.

try:
   num = 5 / 0
except:
   print('An error occurred')
   raise

The assert can take a second argument that is passed to the AssertionError raised if the assertion fails.

@mahdavipanah
mahdavipanah / csslearn-sololearn.md
Last active August 28, 2016 13:15
My notes in learning css via sololearn.com

Inline css styles should be placed in <head>

font-family

The font-family property specifies the font for an element. There are two types of font family names:

  • font family: a specific font family (like Times New Roman or Arial)
  • generic family: a group of font families with a similar look (like Serif or Monospace)

Separate each value with a comma to indicate that they are alternatives.

If the name of a font family is more than one word, it must be in quotation marks: "Times New Roman".

@mahdavipanah
mahdavipanah / producer_consumer.py
Created November 13, 2016 11:06
Solving producer-consumer problem in python using semaphores
"""
Solving producer-consumer problem using semaphores
"""
import threading
# Buffer size
N = 10
# Buffer init
@mahdavipanah
mahdavipanah / array_operation_macro.asm
Last active November 26, 2016 15:16
AVR Assembly examples
.include "m32def.inc"
.macro array_operation
push r16
push xl
push xh
push yl
push yh
push zl
push zh
@mahdavipanah
mahdavipanah / matrix_multiply.py
Created January 17, 2017 08:46
Python matrix multiplication
def matrix_multiply(a, b):
c = [[] for _ in range(len(a))]
for i in range(len(a)):
for j in range(len(a)):
sum = 0
for k in range(len(a)):
sum += a[i][k] * b[k][j]
c[i].append(sum)
return c
@mahdavipanah
mahdavipanah / image_rgb_parts.m
Created March 8, 2017 16:11
Matlab Image Processing
main_image = imread('image.jpg');
red_part = uint8(zeros(size(main_image)));
red_part(:, :, 1) = main_image(:, :, 1);
green_part = uint8(zeros(size(main_image)));
green_part(:, :, 2) = main_image(:, :, 2);
blue_part = uint8(zeros(size(main_image)));
blue_part(:, :, 3) = main_image(:, :, 3);
@mahdavipanah
mahdavipanah / convertToBase.js
Last active July 24, 2017 16:17
Data Structures and Algorithms with JavaScript - Michael McMillan
/**
* Converts a number to another base.
*
* @param {Number} num A number to get converted. If it's float, it's integer part will get converted.
* @param {Number} [base=2] Number's new base.
*
* @returns {String} String representation of number in new base.
*
* @throws {TypeError} First parameter must be a number.
* @throws {RangeError} First Parameter must be >= 0.