Skip to content

Instantly share code, notes, and snippets.

View dongyuwei's full-sized avatar
💭
天天听儿歌

dongyuwei dongyuwei

💭
天天听儿歌
View GitHub Profile
function resizeImage(width, height, maxWidth, maxHeight) {
var ratio = Math.min(maxWidth / width, maxHeight / height);
return { width : width * ratio, height : height * ratio };
}
textarea {
white-space: pre;
display: block;
unicode-bidi: embed;
}
@dongyuwei
dongyuwei / Global keyboard hook for OSX
Created November 2, 2015 13:55 — forked from quietcricket/Global keyboard hook for OSX
OSX global keyboard hook. Requires root privileges.
// alterkeys.c
// http://osxbook.com
//
// Complile using the following command line:
// gcc -Wall -o alterkeys alterkeys.c -framework ApplicationServices
//
// You need superuser privileges to create the event tap, unless accessibility
// is enabled. To do so, select the "Enable access for assistive devices"
// checkbox in the Universal Access system preference pane.
@dongyuwei
dongyuwei / dawg.py
Created October 31, 2015 03:47 — forked from smhanov/dawg.py
Use a DAWG as a map
#!/usr/bin/python3
# By Steve Hanov, 2011. Released to the public domain.
# Updated 2014 to use DAWG as a mapping.
import sys
import time
DICTIONARY = "/usr/share/dict/words"
QUERY = sys.argv[1:]
# This class represents a node in the directed acyclic word graph (DAWG). It
@dongyuwei
dongyuwei / MagickWand-sucks.md
Last active July 25, 2024 19:44
ImportError: MagickWand shared library not found. You probably had not installed ImageMagick library.

Wand==0.3.7, Python 3.4.3, OSX EI Capitan 10.11

when run from wand.image import Image it throw errors:

ImportError: MagickWand shared library not found. You probably had not installed ImageMagick library. Try to install: brew install freetype imagemagick

ok, first I try this:

@dongyuwei
dongyuwei / get_title_and_url.applescript
Last active July 22, 2024 20:12 — forked from vitorgalvao/Get Title and URL.applescript
Applescript to get frontmost tab’s url and title of various browsers.
# Keep in mind that when asking for a `return` after another, only the first one will be output.
# This example is meant as a simple starting point, to show how to get the information in the simplest available way.
# Google Chrome
tell application "Google Chrome" to return URL of active tab of front window
tell application "Google Chrome" to return title of active tab of front window
# Google Chrome Canary
tell application "Google Chrome Canary" to return URL of active tab of front window
tell application "Google Chrome Canary" to return title of active tab of front window
# Chromium
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>CSS responsive images</title>
<style>
@media (min-width:640px) {
.img-box img{
width: 0;
height: 0;
@dongyuwei
dongyuwei / expng.ex
Last active August 29, 2015 14:25 — forked from zabirauf/expng.ex
PNG format Parser in Elixir
defmodule Expng do
defstruct [:width, :height, :bit_depth, :color_type, :compression, :filter, :interlace, :chunks]
def png_parse(<<
0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A,
_length :: size(32),
"IHDR",
width :: size(32),
height :: size(32),
var net = require('net');
var socket = net.connect({
port: 55555 // ssh -N -D 0.0.0.0:55555 localhost
},function() {
console.log('connected to ssh socks server!');
var server = net.createServer(function(client) {
client.pipe(socket);
});
server.listen(1080, '127.0.0.1');
```elixir
:code.all_loaded()
```
```erl
code:all_loaded().
```