Skip to content

Instantly share code, notes, and snippets.

View XuankangLin's full-sized avatar
🐶

ConnorLin XuankangLin

🐶
View GitHub Profile
@XuankangLin
XuankangLin / clipboard.py
Created January 28, 2017 04:20
Read from and Write to clipboards in python scripts, works on Mac at least.
import subprocess
def getClipboardData():
p = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE)
retcode = p.wait()
data = p.stdout.read()
return data
def setClipboardData(data):
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE)
@XuankangLin
XuankangLin / my_volume_control.applescript
Created September 29, 2016 18:24
Volume Up or Volume Down applescript for alfred
on alfred_script(q)
-- your script here
set current to output volume of (get volume settings)
set old to current
set current to current + 10
if (current > 100) then
set current to 100
end if
@XuankangLin
XuankangLin / reformat.py
Created December 22, 2015 20:53
Strip those spaces in copied texts from Kindle app
#!/usr/bin/python
import sys
import os
""" This is for concatenating all the separeted words from Kindle app.. I just
want them be merged again..
Input (copied directly from Kindle app):
@XuankangLin
XuankangLin / Makefile
Created September 14, 2015 16:07
Setting full path in Makefile under some directory
CC=g++
HDIR=./include/
CFILES=main.cpp server.cpp
OUTNAME=server
# Something like this will prepend "./src/" to each of CFILES names, thus setting the correct full path!
CFULL=${CFILES:%=./src/%}
all:
$(CC) -o $(OUTNAME) -pthread -I $(HDIR) $(CFULL)
@XuankangLin
XuankangLin / webwidth.css
Created September 9, 2015 16:14
Simple CSS style for letting web page adjust according to browser size. Not perfect.
@media screen and (min-width: 1000px) {
body {
width: 960px;
margin: auto;
}
}
@media screen and (max-width: 1000px) {
body {
width: 95%;
@XuankangLin
XuankangLin / StickyElement
Created March 3, 2015 06:03
Demonstrate how to make an element stick to the top when user scrolls down too much. Still correct when window is resized. At least work on Safari & Chrome (desktop)..
<html>
<head>
<title>Alice's Adventures in Wonderland -- Chapter I</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
</head>
<body>
<h2>CHAPTER I</h2>
<h2>Down the Rabbit-Hole</h2>
@XuankangLin
XuankangLin / copypb
Created December 19, 2013 16:00
Copy to clipboard in mac os x (in python)
import subprocess
def setClipboardData(data):
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE)
p.stdin.write(data)
p.stdin.close()
retcode = p.wait()
@XuankangLin
XuankangLin / name.html
Created September 10, 2013 00:23
Print out all possible names, given favorite characters and favorite tones. (in Chinese)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="author" content="Andriy Lin"/>
<title>所有名字</title>
<style type="text/css">
body {
margin: 50px;
}
@XuankangLin
XuankangLin / webAudioUtils.js
Created April 23, 2013 06:52
provide several useful functions for handling Web Audio API
// check if support Web Audio
var supportWebAudio = (function(){
// check <audio> tag first
var ele = document.createElement('audio');
if (!ele) {
return false;
}
// check Web Audio's context
try {
@XuankangLin
XuankangLin / high_resolution.html
Created March 15, 2013 01:00
a html that contains two canvas, one being drawn in a normal way, the other being drawn with a context optimized for high resolution displays such as retina displays. You will see it's much clear on safari (for example) on apple devices. However, some methods are not directly compatible with this adaptation. See the modifer class for details.
<!DOCTYPE html>
<html>
<head>
<title> Testing modifying context of canvas. -- Andriy </title>
</head>
<body>
<p>Hello Andriy</p>
<h2>Raw</h2>