Skip to content

Instantly share code, notes, and snippets.

Avatar

Kerem Güneş k-gun

  • Istanbul, Turkey
View GitHub Profile
@kwhat
kwhat / BinaryBaseConvert.php.md
Last active Mar 3, 2020
Binary Base Conversion in PHP
View BinaryBaseConvert.php.md

So, I have come accorss a lot of poor PHP base conversion implementations all over the internet that are unsuitable or incapable of doing large base conversion on binary data. This really isn't a problem for most people in PHP until you start dealing with very large decimals that are sensitive to percision loss, like in cryptography. The following provides two implementations for base conversion that should be safe for large bases and binary data, for example, converting a base256 (binary string) to base85 representation and back again.

Using GMP

You can use GMP to accomplish this at the cost of converting bin<->hex two unneeded times as well as being limited to base62.

<?php
// Not bits, bytes.
$data = openssl_random_pseudo_bytes(256);
View weighted.go
package main
import (
"errors"
"fmt"
"math/rand"
"time"
)
type Game struct {
@hollodotme
hollodotme / Install-nginx-with-http2-support.md
Created Apr 9, 2016
Install nginx with http2 support on ubuntu 14.04 LTS (Trusty)
View Install-nginx-with-http2-support.md

How to install nginx (>= 1.9.5) with http2 support on Ubuntu 14.04 LTS (Trusty)

IMPORTANT: Backup your nginx site configs (usually under /etc/nginx/sites-available)!

Remove old nginx

Remove old nginx incl. nginx-common:

apt-get autoremove --purge nginx nginx-common
@gwillem
gwillem / magento-nginx.conf
Last active Aug 4, 2020
Battle-tested Nginx configuration for Magento (source: www.hypernode.com)
View magento-nginx.conf
# This is an annotated subset of the Nginx configuration from our Magento production platform @ www.hypernode.com
# See https://www.byte.nl/blog/magento-cacheleak-issue
# !!!! If you are a Hypernode customer, do not use this config as it will result in duplicate statements. !!!!!
user app;
worker_processes 4;
pid /var/run/nginx.pid;
events {
@tronsha
tronsha / installphp7.sh
Last active May 9, 2020
Install PHP7 to Ubuntu
View installphp7.sh
#!/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
View eventListenerList.js
;[Element].forEach(function(self){
self.prototype.eventListenerList = {};
self.prototype._addEventListener = self.prototype.addEventListener;
self.prototype.addEventListener = function(type, handle, useCapture) {
useCapture = useCapture === void 0 ? false : useCapture;
var node = this;
node._addEventListener(type, handle, useCapture);
@h4cc
h4cc / createMongoDbLikeId.php
Created Aug 3, 2014
A PHP function to generate IDs like MongoDB uses with its ObjectIDs
View createMongoDbLikeId.php
<?php
/**
* Creating MongoDB like ObjectIDs.
* Using current timestamp, hostname, processId and a incremting id.
*
* @author Julius Beckmann
*/
function createMongoDbLikeId($timestamp, $hostname, $processId, $id)
{
@kendellfab
kendellfab / goto-sublime
Created Aug 1, 2013
Add mouse click `goto definition` in sublime text 3.
View goto-sublime
Linux - create "Default (Linux).sublime-mousemap" in ~/.config/sublime-text-3/Packages/User
Mac - create "Default (OSX).sublime-mousemap" in ~/Library/Application Support/Sublime Text 3/Packages/User
Win - create "Default (Windows).sublime-mousemap" in %appdata%\Sublime Text 3\Packages\User
[
{
"button": "button1",
"count": 1,
"modifiers": ["ctrl"],
"press_command": "drag_select",
@meSingh
meSingh / sublime-text-installation-instructions.md
Last active Jun 7, 2020
Sublime Text Installation Instructions for Ubuntu 13.04 and Elementary OS Luna
View sublime-text-installation-instructions.md

Sublime Text 2 Installation Guide: Ubuntu 13.04 and Elementary OS Luna

1. Install Sublime Text 2

Open terminal

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text

2. Install Sublime Package Control

View jquery.ajaxqueue.js
/*
Allows for ajax requests to be run synchronously in a queue
Usage::
var queue = new $.AjaxQueue();
queue.add({
url: 'url',
You can’t perform that action at this time.