Skip to content

Instantly share code, notes, and snippets.

@bdunogier
bdunogier / curl_progress.php
Created June 16, 2011 22:31
PHP/cURL download progress monitoring
<?php
file_put_contents( 'progress.txt', '' );
$targetFile = fopen( 'testfile.iso', 'w' );
$ch = curl_init( 'http://ftp.free.org/mirrors/releases.ubuntu-fr.org/11.04/ubuntu-11.04-desktop-i386-fr.iso' );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt( $ch, CURLOPT_NOPROGRESS, false );
curl_setopt( $ch, CURLOPT_PROGRESSFUNCTION, 'progressCallback' );
curl_setopt( $ch, CURLOPT_FILE, $targetFile );
@marianposaceanu
marianposaceanu / latency.md
Created May 31, 2012 10:18 — forked from jboner/latency.txt
Latency numbers every programmer should know

CPU

  • L1 cache reference 0.5 ns
  • Branch mispredict 5 ns (on a bad CPU architecture you're pretty much screwed)
  • L2 cache reference 7 ns
  • Mutex lock/unlock 25 ns
  • Main memory reference 100 ns
  • Compress 1K bytes with Zippy 3,000 ns
  • Send 2K bytes over 1 Gbps network 20,000 ns
  • Read 1 MB sequentially from memory 250,000 ns
@taterbase
taterbase / system-beep.js
Created July 21, 2012 05:01
System Beep in Node.js
function alertTerminal(){
console.log("\007");
}
@gkmuse
gkmuse / KEY.bat
Created August 1, 2012 15:04
Generate Random String of Arbitrary Length with Batch
@echo off
setlocal EnableDelayedExpansion
set char=abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
set count=0
set salt=0
echo The maximum RC4 key length is 128 bits.
echo Default KEY length is 16 characters.
@marianposaceanu
marianposaceanu / linux_performance.md
Last active January 30, 2024 06:47
Linux simple performance tweaks

Linux simple performance tweaks

Change the I/O Scheduler

Open $ vim /etc/default/grub then add elevator=noop next to GRUB_CMDLINE_LINUX_DEFAULT. Run $ update-grub and $ cat /sys/block/sda/queue/scheduler to be sure that noop is being used:

$ vim /etc/default/grub
$ update-grub
$ cat /sys/block/sda/queue/scheduler

[noop] deadline cfq

@tony4d
tony4d / mysqldump-backup.sh
Last active June 11, 2019 03:28
Backup all databases on a mysql server excluding information/performance_schema and including UDFs/stored procedures. Most useful scheduling this on a slave db.
#!/bin/bash
# No username or passwords in this script, you should use mysql_config_editor
# to store it securely. The login-path in this script is set to "local-backup" so when you create
# your .mylogin.cnf with the mysql-config-editor make sure it is set the same
# See http://dev.mysql.com/doc/refman/5.6/en/mysql-config-editor.html
# An example to create your config for a mysql user "backup":
# shell> sudo mysql_config_editor set --login-path=local-backup --host=localhost --user=backup --password
# The backup user in the mysql server needs these privileges: SELECT, RELOAD, SHOW DATABASES, REPLICATION CLIENT
@atatos
atatos / Autocomplete JSON & Bold Hightlighted
Created July 27, 2013 17:30
this is an example of the autocomplete jQuery ui ( JSON & Bold hightlighted)
$("#search-txt").autocomplete({
source: function (req, responseFn) {
$.ajax({
url: "/search.json",
dataType: "json",
success: function(data) {
var re = $.ui.autocomplete.escapeRegex(req.term);
var matcher = new RegExp( "^" + re, "i" );
@sepehr
sepehr / in_arrayi.php
Created August 27, 2013 09:12
PHP: Case-insensitive in_array()
<?php
/**
* Case-insensitive in_array() wrapper.
*
* @param mixed $needle Value to seek.
* @param array $haystack Array to seek in.
*
* @return bool
*/
@tommybutler
tommybutler / smartcheck.sh
Last active May 23, 2024 20:42
Script to quickly scan the S.M.A.R.T. health status of all your hard drive devices in Linux (at least all the ones from /dev/sda to /dev/sdzz). You need smartctl installed on your system for this script to work, and your hard drives need to have S.M.A.R.T. capabilities (they probably do).
#!/bin/bash
# install the smartctl package first! (apt-get install smartctl)
if sudo true
then
true
else
echo 'Root privileges required'
@aeris
aeris / gpgit.py
Last active April 11, 2018 12:11
Automatically GPG encrypt all possible incoming email.Don't encrypt plain-text or clear-sign GPG sign to avoid breaking the sign
#!/usr/bin/env python
# GPGIt : Automatically GPG-encrypt incoming email
# Aeris <aeris@imirhil.fr>
# Licensed under AGPLv3 or later
import email
import sys, os
import re
from pyme.core import Data, Context
from email.mime.base import MIMEBase