Skip to content

Instantly share code, notes, and snippets.

View ximik777's full-sized avatar

Grigoriy Stratov ximik777

View GitHub Profile
@ximik777
ximik777 / hash.c
Last active August 29, 2015 14:10 — forked from tonious/hash.c
#define _XOPEN_SOURCE 500 /* Enable certain library functions (strdup) on linux. See feature_test_macros(7) */
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
struct entry_s {
char *key;
char *value;
<?php
// Ab PHP 5.4 steht für json_encode die Konstante JSON_PRETTY_PRINT zur Verfügung.
echo json_encode($arr, JSON_PRETTY_PRINT);
// Für PHP <= 5.3 gibt es folgende Alternative (Quelle Zend):
/**
* Pretty-print JSON string
*
@ximik777
ximik777 / async_dns.c
Created October 30, 2015 00:03 — forked from mopemope/async_dns.c
c-ares example
#include <ares.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
@ximik777
ximik777 / ares.c
Created October 30, 2015 12:09
static gethostbyname with libcares
#include <ares.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
@ximik777
ximik777 / php-start-stop-daemon.sh
Created November 2, 2015 22:03
Run a PHP script as a service/daemon using start-stop-daemon
#! /bin/sh
# Installation
# - Move this to /etc/init.d/myservice
# - chmod +x this
#
# Starting and stopping
# - Start: `service myservice start` or `/etc/init.d/myservice start`
# - Stop: `service myservice stop` or `/etc/init.d/myservice stop`
<?php
/*! @class SocketServer
@author Navarr Barnier
@abstract A Framework for creating a multi-client server using the PHP language.
*/
class SocketServer
{
/*! @var config
@abstract Array - an array of configuration information used by the server.
*/
//http://stackoverflow.com/questions/10717190/convert-svg-polygon-to-path
//Open your SVG in a web browser.
//Run this code:
var polys = document.querySelectorAll('polygon,polyline');
[].forEach.call(polys,convertPolyToPath);
function convertPolyToPath(poly){
var svgNS = poly.ownerSVGElement.namespaceURI;
@ximik777
ximik777 / installphp7.sh
Created March 4, 2016 21:48 — forked from tronsha/installphp7.sh
Install PHP7 to Ubuntu
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
apt-get update
apt-get install -y git-core autoconf bison libxml2-dev libbz2-dev libmcrypt-dev libcurl4-openssl-dev libltdl-dev libpng-dev libpspell-dev libreadline-dev make
mkdir -p /etc/php7/conf.d
mkdir -p /etc/php7/cli/conf.d
mkdir /usr/local/php7
@ximik777
ximik777 / card.php
Created July 7, 2016 15:26
Conversion ID cards in all formats
<?php
function cardList($card_id, $uppercase = false)
{
if (!$card_id) return [];
$arr = [];
$arr[0] = $card_id;
$arr[1] = implode(array_reverse(str_split($card_id, 2)));
if (preg_match('/^[0-9]*$/', $card_id)) {
@ximik777
ximik777 / card.js
Last active July 7, 2016 15:30
Conversion ID cards in all formats
function cardList(card_id, upeercase) {
if (!card_id) return [];
card_id += '';
upeercase = !!(upeercase);
var arr = [],
dechex = function (number) {
return parseInt(number < 0 ? 0xFFFFFFFF + number + 1 : number, 10).toString(16)
}, str_split = function (str, split) {
if (!str) return false;
split = split || 1;