Skip to content

Instantly share code, notes, and snippets.

View smarteist's full-sized avatar
🙂
I may be slow to respond.

Ali Hosseini smarteist

🙂
I may be slow to respond.
View GitHub Profile
@smarteist
smarteist / conditional_variable.c
Last active May 12, 2023 14:28
conditional variable api using semaphores!
#include <stdio.h>
#include <pthread.h>
#include <semaphore.h>
#include <unistd.h>
typedef struct {
sem_t wait_sem;
sem_t signal_sem;
int value;
} cond_var_t;
@smarteist
smarteist / sbrk.c
Last active April 22, 2023 15:52
allocate two pages, in C
#include <stdio.h>
#include <unistd.h>
#include <sys/syscall.h>
// same as calling sbrk(0)
void *get_brk (void)
{
return (void *) syscall (SYS_brk, 0);
}
@smarteist
smarteist / default.conf
Last active March 2, 2022 17:14
This is a local webserver configuration for nginx on LEMP stack plus phpmyadmin.
server {
listen 80;
listen [::]:80;
#listen 443 ssl http2;
server_name localhost .localhost;
charset utf-8;
root "/srv/www/nginx/";
index index.php index.html index.htm;
gzip off;
@smarteist
smarteist / view.php
Created July 15, 2021 08:11
How to render views in php
<?php
function renderView($filePath, $variables = array(), $print = true)
{
$output = NULL;
if(file_exists($filePath)){
// Start output buffering
ob_start();
@smarteist
smarteist / toGeneralChar.html
Last active June 14, 2021 07:22
Arabic and Persian Characters to general form
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
@smarteist
smarteist / xdebug-on-linux.md
Last active June 11, 2021 05:11
PHP xDebug on Linux/Mac and phpStorm

Install and Configure xDebug 🪲 on Linux for PhpStorm 🐘

  • Assuming that you have already installed php and apache
  • Install xDebug php extension

# Arch Linux , Manjaro
sudo pacman -Sy xdebug

# Ubuntu 16.04,18.04

General Form

<major>.<minor>.<patch> ==example==> 1.2.3

<major>.<minor>.<patch>-beta.<beta> ==example==> 1.2.3-beta.2

Version Prefix

@smarteist
smarteist / Laravel-Container.md
Created January 5, 2021 17:44
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

@smarteist
smarteist / print.js
Last active October 29, 2020 14:45
create printable window with java script
jQuery(document).ready(function ($) {
$("#printme").click(function () {
var bodyContent = '';
$('body').find('.printable').each(function (index, object) {
bodyContent += $(object).html();
});
var headStyles = '';
$('head').find('link[rel="stylesheet"]').each(function (index, object) {
headStyles += '<link href="' + $(object).attr('href') + '" rel="stylesheet"/>';
@smarteist
smarteist / InfiniteScrollProvider.java
Last active October 4, 2020 06:58
Android recyclerView Infinite Scrolling (Endless Scrolling)
package com.nodano.memo.utils.AppUtils;
import androidx.annotation.NonNull;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import android.content.res.Resources;