Skip to content

Instantly share code, notes, and snippets.

View dingjie's full-sized avatar

dingjie

  • Musion Ltd.
  • Shenzhen, China
View GitHub Profile
@dingjie
dingjie / open.php
Created March 17, 2019 10:54
Controll GPIO in Raspberry Pi (PHP)
<?php
require('vendor/autoload.php');
use PiPHP\GPIO\GPIO;
use PiPHP\GPIO\Pin\PinInterface;
// Create a GPIO object
$gpio = new GPIO();
// Retrieve pin 18 and configure it as an output pin
@dingjie
dingjie / 0_reuse_code.js
Created December 4, 2015 16:20
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@dingjie
dingjie / strongvpn.py
Last active November 29, 2015 09:58
Strong vpn speed test
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import socket
import threading
import workerpool
import json
from pprint import pprint
@dingjie
dingjie / dog.fish
Last active November 28, 2015 19:47
Coloured version of cat
function dog
for x in $argv
if not test -f $x
echo "$x does not exist or cannot be barked at"
else if not test -r $x
echo "$x cannot be read"
else if perl -E 'exit((-B $ARGV[0])?0:1);' $x
echo "$x is a binary file"
else
file $x
@dingjie
dingjie / applocale.sh
Last active November 12, 2015 08:12
Set default language of application in Mac
#!/bin/sh
# Example: ./applocale.sh QQ zh-CN
if [ "$#" -ne 2 ]; then
echo "Usage: $0 [app name] [locale]"
exit 1
fi
CMD="/usr/bin/defaults"
OSASCRIPT="/usr/bin/osascript"
@dingjie
dingjie / overflow.coffee
Last active October 30, 2015 16:27
Prevent to scroll parent layer when div ends
# https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight
@div.bind 'mousewheel DOMMouseScroll', (e) ->
d = e.originalEvent.wheelDelta or -e.originalEvent.detail
e.preventDefault() if ((@scrollHeight - @scrollTop) <= @clientHeight and d < 0) or (@scrollTop <= 0 and d > 0)
Ember.Handlebars.registerHelper('eachIndexed', function eachHelper(path, options) {
var keywordName = 'item',
fn;
// Process arguments (either #earchIndexed bar, or #earchIndexed foo in bar)
if (arguments.length === 4) {
Ember.assert('If you pass more than one argument to the eachIndexed helper, it must be in the form #eachIndexed foo in bar', arguments[1] === 'in');
Ember.assert(arguments[0] + ' is a reserved word in #eachIndexed', $.inArray(arguments[0], ['index', 'index+1', 'even', 'odd']));
keywordName = arguments[0];
#!/bin/bash
# From http://markmcb.com/2013/02/04/cleanup-unused-linux-kernels-in-ubuntu/
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge
#!/usr/bin/python
LISTEN_PORT = 18080
from twisted.internet import protocol, reactor
from ProxySelector import ProxySelector
import csv, random
class ProxySelector:
@dingjie
dingjie / gist:9534262
Last active August 29, 2015 13:57
Text to Image
<?php
function text2img($text, $size, $color, $font='kangxi.otf') {
$draw = new ImagickDraw();
$draw->setGravity(Imagick::GRAVITY_CENTER);
$draw->setFont($font);
$draw->setFontSize($size);
$draw->setFillColor(new ImagickPixel($color));
$im = new imagick();
$metric = $im->queryFontMetrics($draw, $text);