Skip to content

Instantly share code, notes, and snippets.

@hanvari
hanvari / serve_download.php
Created August 25, 2014 21:39
PHP Serve File for Download
<?php
function DownloadFile($file) {
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
# header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
@hanvari
hanvari / PDO_Cheatsheet.php
Created August 25, 2014 22:11
PHP PDO Cheatsheet
<?php
/*
Reference:
http://code.tutsplus.com/tutorials/why-you-should-be-using-phps-pdo-for-database-access--net-12059
*/
function connect(){
/*
@hanvari
hanvari / mysql-disable-foreign-check.sql
Last active August 29, 2015 14:06
MySQL Disable foreign-key checks to truncate a table
SET FOREIGN_KEY_CHECKS=0;
truncate table schema.table ;
SET FOREIGN_KEY_CHECKS=1;
sudo /Applications/Install\ OS\ X\ El\ Capitan.app/Contents/Resources/createinstallmedia --volume /Volumes/elcapitaninstaller --applicationpath /Applications/Install\ OS\ X\ El\ Capitan.app –nointeraction
javascript:(function({
var INSTAPAPER=true,w=window,d=document,pageSelectedTxt=w.getSelection?w.getSelection():(d.getSelection)?d.getSelection():(d.selection?d.selection.createRange().text:0),pageTitle=d.title,pageUri=w.location.href,tmplt="";
tmplt="From ["+pageTitle+"]("+pageUri+"):\n\n";
if(pageSelectedTxt!="") {
pageSelectedTxt=">%20"+pageSelectedTxt;
pageSelectedTxt=pageSelectedTxt.replace(/(\r\n|\n+|\r)/gm,"\n");
pageSelectedTxt=pageSelectedTxt.replace(/\n/g,"\n>%20\n>%20");
w.location.href="nvalt://make/?txt="+encodeURIComponent(tmplt+pageSelectedTxt)+"&title="+encodeURIComponent(pageTitle)
}
else {
@hanvari
hanvari / hadoop-quick-start.md
Last active January 4, 2017 05:55
Apache Hadoop Quick Start
@hanvari
hanvari / sigchld_avoid_zombies.md
Created January 25, 2017 02:05
Avoiding zombie processes by handling SIGCHLD

We could simply set the SIGCHLD signal to be handled by SIG_IGN (ignored), and based on POSIX.1-2001 it will clean up the terminated child process.

struct sigaction sa;
sa.sa_handler = SIG_IGN;
sigemptyset(&sa.sa_mask);
sa.sa_flags = 0;
if (sigaction(SIGCHLD, &sa, 0) == -1) {
  perror(0);
  exit(1);
}
@hanvari
hanvari / git-overwrite-local.md
Created January 27, 2017 16:26
Git overwrite local changes with remote version
git fetch --all
git reset --hard origin/master
git pull origin master
@hanvari
hanvari / macos-heimdall-compile.sh
Created June 6, 2017 09:17
Build Heimdall on MacOS Sierra
git clone git@github.com:Benjamin-Dobell/Heimdall.git
cd Heimdall
mkdir build
cd build
cmake -DDISABLE_FRONTEND=ON -DCMAKE_BUILD_TYPE=Release ..
LIBRARY_PATH=/usr/local/lib make
#References:
#https://raw.githubusercontent.com/Benjamin-Dobell/Heimdall/master/Linux/README
@hanvari
hanvari / TestSSDPerformance.sh
Last active August 3, 2017 15:20
Benchmarking Disk access performance to detect SSD (or very high-speed HDD)
#reading 1000 random 4k blocks from first 16GB of a disk
time for i in `seq 1 1000`; do
dd bs=4k if=/dev/sda count=1 skip=$(( $RANDOM * 128 )) >/dev/null 2>&1;
done
#References:
# https://unix.stackexchange.com/questions/65595/how-to-know-if-a-disk-is-an-ssd-or-an-hdd
# https://serverfault.com/questions/551453/how-do-i-verify-that-my-hosting-provider-gave-me-ssds/551495#551495