Skip to content

Instantly share code, notes, and snippets.

View shakahl's full-sized avatar
:electron:

Soma Szelpal shakahl

:electron:
View GitHub Profile
<?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 );
/**
*
* Using CURL to download partial content from a URL
*
* @url file URL to download
* @range_start Start range in bytes
* @range_end End range in bytes
*
*
* example: curl_get_content("http://www.example.org/some-file.zip",100,500)
@shakahl
shakahl / SecureSessionHandler.php
Last active August 29, 2015 14:25 — forked from eddmann/SecureSessionHandler.php
Secure session handler implementation.
<?php
class SecureSessionHandler extends SessionHandler {
protected $key, $name, $cookie;
public function __construct($key, $name = 'MY_SESSION', $cookie = [])
{
$this->key = $key;
$this->name = $name;
@shakahl
shakahl / findauthors.sh
Created October 11, 2015 20:10 — forked from stefanfoulis/findauthors.sh
How to sync svn to git
#!/usr/bin/env bash
# Run this script inside a SVN checkout of the project
authors=$(svn log -q | grep -e '^r' | awk 'BEGIN { FS = "|" } ; { print $2 }' | sort | uniq)
for author in ${authors}; do
echo "${author} = NAME <USER@DOMAIN>";
@shakahl
shakahl / send_remote_syslog.php
Created December 29, 2015 22:21 — forked from troy/send_remote_syslog.php
Send UDP remote syslog message from PHP (RFC 3164)
# replace PAPERTRAIL_HOSTNAME and PAPERTRAIL_PORT
# see http://help.papertrailapp/ for additional PHP syslog options
function send_remote_syslog($message, $component = "web", $program = "next_big_thing") {
$sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
foreach(explode("\n", $message) as $line) {
$syslog_message = "<22>" . date('M d H:i:s ') . $program . ' ' . $component . ': ' . $line;
socket_sendto($sock, $syslog_message, strlen($syslog_message), 0, PAPERTRAIL_HOSTNAME, PAPERTRAIL_PORT);
}
socket_close($sock);
@shakahl
shakahl / sphinx.conf
Created January 15, 2016 20:05 — forked from fideloper/sphinx.conf
Install Sphinx and php .so in Ubuntu 12.04
#############################################################################
## data source definitions
#############################################################################
source users
{
# data source type. mandatory, no default value
# known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc
type = mysql
@shakahl
shakahl / mkrole
Created July 20, 2016 09:44 — forked from proxypoke/mkrole
mkrole - create an ansible role skeleton
#!/bin/sh
# create the directory structure and some files
# for an ansible role
ROLE=$1
if [ -z "$ROLE" ]; then
echo "need a role name"
exit 1
fi
@shakahl
shakahl / main.yml
Created July 27, 2016 12:42 — forked from rothgar/main.yml
Generate /etc/hosts with Ansible
# Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source.
# Will include all hosts the playbook is run on.
# Inspired from http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html
- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']
@shakahl
shakahl / pedantically_commented_playbook.yml
Created August 29, 2016 09:34 — forked from marktheunissen/pedantically_commented_playbook.yml
Insanely complete Ansible playbook, showing off all the options
---
# ^^^ YAML documents must begin with the document separator "---"
#
#### Example docblock, I like to put a descriptive comment at the top of my
#### playbooks.
#
# Overview: Playbook to bootstrap a new host for configuration management.
# Applies to: production
# Description:
# Ensures that a host is configured for management with Ansible.
@shakahl
shakahl / nginx cloudflare
Created September 27, 2016 09:40 — forked from todiadiyatmo/nginx cloudflare
nginx cloudflare
#CloudFlare
set_real_ip_from 103.21.244.0/22;
set_real_ip_from 103.22.200.0/22;
set_real_ip_from 103.31.4.0/22;
set_real_ip_from 104.16.0.0/12;
set_real_ip_from 108.162.192.0/18;
set_real_ip_from 141.101.64.0/18;
set_real_ip_from 162.158.0.0/15;
set_real_ip_from 172.64.0.0/13;
set_real_ip_from 173.245.48.0/20;