Skip to content

Instantly share code, notes, and snippets.

View tacone's full-sized avatar
💭
¯\_(ツ)_/¯

tacone

💭
¯\_(ツ)_/¯
View GitHub Profile
@splatch
splatch / jquery.http.js
Created April 14, 2011 16:17
Extra http methods for jQuery based on X-HTTP-Method-Override header.
function _ajax_request(url, data, callback, type, method) {
if (jQuery.isFunction(data)) {
callback = data;
data = {};
}
return jQuery.ajax({
type: "POST",
url: url,
data: data,
@thiagophx
thiagophx / benchmark.php
Created September 28, 2011 13:04
Object creation in PHP, which approach is faster? new, clone or unserialize???
<?php
function leSerialize()
{
for ($i = 0; $i < 1000; $i++)
unserialize('O:8:"stdClass":0:{}');
}
function leNew()
{
@conradlee
conradlee / edgelist2pajek.py
Created November 1, 2011 16:48
Converts edgelists to pajek files. Works for very large files.
#!/usr/bin/env python
import os
import sys
import subprocess
import optparse
import tempfile
# Special feature: can convert files so large that they
# don't fit in memory. Works for weighted/unweighted,
# directed/undirected edges.
@mardix
mardix / php-cs-fixer-pre-commit.php
Created September 4, 2012 17:06
A pre-commit hook to make PHP code PSR-2 compliant, check for syntax error
#!/usr/bin/php
<?php
/**
* .git/hooks/pre-commit
*
* This pre-commit hooks will check for PHP error (lint), and make sure the code
* is PSR compliant.
*
* Dependecy: PHP-CS-Fixer (https://github.com/fabpot/PHP-CS-Fixer)
*
@denji
denji / nginx-tuning.md
Last active June 13, 2024 14:05
NGINX tuning for best performance

Moved to git repository: https://github.com/denji/nginx-tuning

NGINX Tuning For Best Performance

For this configuration you can use web server you like, i decided, because i work mostly with it to use nginx.

Generally, properly configured nginx can handle up to 400K to 500K requests per second (clustered), most what i saw is 50K to 80K (non-clustered) requests per second and 30% CPU load, course, this was 2 x Intel Xeon with HyperThreading enabled, but it can work without problem on slower machines.

You must understand that this config is used in testing environment and not in production so you will need to find a way to implement most of those features best possible for your servers.

@dergachev
dergachev / squid-deb-proxy_on_docker.md
Last active May 25, 2023 03:55
Caching debian package installation with docker

TLDR: I now add the following snippet to all my Dockerfiles:

# If host is running squid-deb-proxy on port 8000, populate /etc/apt/apt.conf.d/30proxy
# By default, squid-deb-proxy 403s unknown sources, so apt shouldn't proxy ppa.launchpad.net
RUN route -n | awk '/^0.0.0.0/ {print $2}' > /tmp/host_ip.txt
RUN echo "HEAD /" | nc `cat /tmp/host_ip.txt` 8000 | grep squid-deb-proxy \
  && (echo "Acquire::http::Proxy \"http://$(cat /tmp/host_ip.txt):8000\";" > /etc/apt/apt.conf.d/30proxy) \
  && (echo "Acquire::http::Proxy::ppa.launchpad.net DIRECT;" >> /etc/apt/apt.conf.d/30proxy) \
  || echo "No squid-deb-proxy detected on docker host"
@bruceoutdoors
bruceoutdoors / DbmigrateController.php
Last active May 25, 2024 11:41
Laravel 4 Convert existing MySQL database to migrations. This is a fork of Christopher Pitt's work http://laravelsnippets.com/snippets/convert-an-existing-mysql-database-to-migrations, which is based off michaeljcalkins's work at http://paste.laravel.com/1jdw#sthash.0nEgQzQR.dpuf. His original source code doesn't really work out of the box in my…
<?php
/* * **
*
* This script converts an existing MySQL database to migrations in Laravel 4.
*
* 1. Place this file inside app/controllers/
*
* 2. In this file, edit the index() method to customize this script to your needs.
* - inside $migrate->ignore(), you pass in an array of table
@wancw
wancw / timereport.plugin.zsh
Last active August 29, 2015 14:02
Report elapsed time for command take long time to execute.
typeset -gaU preexec_functions
typeset -gaU precmd_functions
preexec_functions+='preexec_start_timer'
precmd_functions+='precmd_report_time'
_tr_current_cmd="?"
_tr_sec_begin="${SECONDS}"
_tr_ignored="yes"
@zofe
zofe / routes.php
Last active August 29, 2015 14:07
Internal router for rapyd-laravel that match "uri" and/or "query string", it can run before Laravel to Fire widget events
<?php namespace Zofe\Rapyd;
/**
* Class Router
* the rapyd router, works "before" laravel router to check uri/query string
* it set widgets status / actions.
*
* @package Zofe\Rapyd
*
* @method public static get($uri=null, $query=null, Array $route)
@enil
enil / wait
Created June 5, 2015 17:00
Wait for user to press any key in ZSH
#!/bin/zsh
echo 'Press any key to continue...'; read -k1 -s