Skip to content

Instantly share code, notes, and snippets.

View consatan's full-sized avatar

Chopin Ngo consatan

  • Amoy, Fujian, China
View GitHub Profile
@upsuper
upsuper / gist:5351509
Created April 10, 2013 03:22
Simplify IP segments by removing redundant segments and merging adjacent segments.
# coding: UTF-8
import socket
import struct
def aton(addr):
return struct.unpack('!l', socket.inet_aton(addr))
def ntoa(addr):
return socket.inet_ntoa(struct.pack('!l', addr))
@farinspace
farinspace / combos.php
Last active February 4, 2021 11:56
Recursive functions, I can never find exactly what I need in a pinch
<?php
function combos($data, &$all = array(), $group = array(), $val = null, $i = 0) {
if (isset($val)) {
array_push($group, $val);
}
if ($i >= count($data)) {
array_push($all, $group);
} else {
foreach ($data[$i] as $v) {
@jimblom
jimblom / certs.sh
Last active May 23, 2022 16:27
Update Java cacerts
#!/bin/sh
# certs.sh
# use this for Yocto/Edison:
LIB=lib
# use this for WRLinux/Gateway
# LIB=lib64
if [ -f /usr/$LIB/jvm/java-8-openjdk/jre/lib/security/cacerts ]; then
mv /usr/$LIB/jvm/java-8-openjdk/jre/lib/security/cacerts \
@kumatch
kumatch / daemon.js
Created March 25, 2013 01:49
Node.js daemon example
var fs = require('fs');
var INTERVAL = 1000;
var cycle_stop = false;
var daemon = false;
var timer;
process.argv.forEach(function (arg) {
if (arg === '-d') daemon = true;
@amirbehzad
amirbehzad / phpunit_pdo_mock.php
Created January 21, 2016 04:18
How to mock PDO for test-cases written in PHPUnit
<?php
// ...
protected function getMockedPDO()
{
$query = $this->getMock('\PDOStatement');
$query->method('execute')->willReturn(true);
$db = $this->getMockBuilder('\PDO')
->disableOriginalConstructor()
@IQAndreas
IQAndreas / caesar-cipher.sh
Last active August 30, 2023 09:39
A really simple Caesar Cipher in Bash (or Shell) using `tr`, can also easily be adjusted to encrypt/decrypt ROT13 instead.
# Caesar cipher encoding
echo "THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG" | tr '[A-Z]' '[X-ZA-W]'
# output: QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD
# Caesar cipher decoding
echo "QEB NRFZH YOLTK CLU GRJMP LSBO QEB IXWV ALD" | tr '[X-ZA-W]' '[A-Z]'
# output: THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG
# Can also be adjusted to ROT13 instead
@chadrien
chadrien / README.md
Last active September 1, 2023 12:43
Debug PHP in Docker with PHPStorm and Xdebug

Debug your PHP in Docker with Intellij/PHPStorm and Xdebug

  1. For your local dev, create a Dockerfile that is based on your production image and simply install xdebug into it. Exemple:
FROM php:5

RUN yes | pecl install xdebug \
&amp;&amp; echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" &gt; /usr/local/etc/php/conf.d/xdebug.ini \
#!/bin/sh
import(){
img_name=$1
vm_id=$2
storage=${3:-local-lvm}
vmdisk_name=img2kvm_temp.qcow2
if [ "${img_name##*.}"x = "gz"x ];then
$.fn.select2.amd.define('select2/data/extended-ajax',['./ajax','../utils','jquery'], function(AjaxAdapter, Utils, $){
function ExtendedAjaxAdapter ($element,options) {
//we need explicitly process minimumInputLength value
//to decide should we use AjaxAdapter or return defaultResults,
//so it is impossible to use MinimumLength decorator here
this.minimumInputLength = options.get('minimumInputLength');
this.defaultResults = options.get('defaultResults');
ExtendedAjaxAdapter.__super__.constructor.call(this,$element,options);
@ikawka
ikawka / cloudflare-trace.js
Last active December 31, 2023 12:29
Trace current user's location via javascript with CloudFlare provided the /cdn-cgi/trace is enabled.
(function($){
$(function(){
$.ajax({
contentType: 'application/text; charset=utf-8',
crossBrowser: true,
type: 'GET',
url: '/cdn-cgi/trace',
}).done(function(d){
var data = d.replace(/[\r\n]+/g, '","').replace(/\=+/g, '":"');
data = '{"' + data.slice(0, data.lastIndexOf('","')) + '"}';