Skip to content

Instantly share code, notes, and snippets.

View fourdollars's full-sized avatar
🏠
Working from home

Shih-Yuan Lee (FourDollars) fourdollars

🏠
Working from home
View GitHub Profile
@fourdollars
fourdollars / num.sh
Last active November 23, 2016 12:42
Print numbers in sequence without repeated digits. https://www.ptt.cc/bbs/Programming/M.1479904715.A.DD6.html
#! /usr/bin/env bash
read -p 'Enter a number : ' num
seq $((10**num)) | egrep -v "([0-9]).*\1" | xargs echo | sed 's/ /, /g'
#!/usr/bin/python3
import random, re
collection = ('A1-1', 'A1-2', 'A1-3', 'A1-4', 'A1-5', 'A1-6', 'A1-7', 'A1-8', 'A1-9', 'A1-10', 'A1-11', 'A1-12', 'A1-13', 'A1-14', 'A2-1', 'A2-3', 'A2-4', 'A2-5', 'A2-6', 'A2-7', 'A2-8', 'A2-9', 'A2-10', 'A2-11', 'A2-12', 'A2-13', 'A2-14', 'A3-1', 'B1-3', 'B1-4', 'B1-5', 'B1-6', 'B1-7', 'B1-8', 'B1-9', 'B1-10', 'B1-11', 'B1-12', 'B2-3', 'B2-4', 'B2-5', 'B2-6', 'B2-7', 'B2-8', 'B2-9', 'B2-10', 'B2-11', 'B2-12')
print('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><title>機車腳踏車車位選填志願抽籤結果</title>')
print('''<style>
table {border: 0; border-collapse: collapse; width: 100%; table-layout: fixed;}
td,th {border: 1px solid black;}
var scores = [98, 74, 85, 77, 93, 100, 89];
var total = 0;
for (var score in scores) {
total += score;
}
var mean = total / scores.length;
console.log(mean);
@fourdollars
fourdollars / game.js
Last active December 19, 2015 10:52
An example from Effective JavaScript
function Scene(context, width, height, images) {
this.context = context;
this.width = width;
this.height = height;
this.images = images;
this.actors = [];
}
Scene.prototype.register = function(actor) {
this.actors.push(actor);
#! /usr/bin/env python3
def find_duplicate(vbt_min, pwm_max):
prev = -1
pwm_min = round(vbt_min * pwm_max / 255)
print("sysfs : PWM")
print("-----------")
for i in range(pwm_max + 1):
pwm = round(i * (pwm_max - pwm_min) / pwm_max + pwm_min)
if prev == pwm:
@fourdollars
fourdollars / list.sh
Last active November 2, 2015 07:31
Please replace [...] with your code snippets. This script will be used in busybox to find out the partitions by following the specific order.
#!/bin/sh
PARTITIONS="/dev/mmcblk0p1 /dev/mmcblk1p1 /dev/nvm0n1p1 /dev/nvm0n2p1 /dev/sda1 /dev/sdb1"
DEVICES="/dev/sdb /dev/nvm0n2 /dev/nvm0n1 /dev/mmcblk0"
result=""
[...] # can not use PARTITIONS here
for partition in $PARTITIONS; do
/usr/bin/kore:
Position Independent Executable: yes
Stack protected: yes
Fortify Source functions: yes (some protected functions found)
unprotected: read
unprotected: poll
unprotected: fgets
unprotected: memset
unprotected: getcwd
unprotected: memcpy
@fourdollars
fourdollars / gist:6b457a63b26d89d9cbd9
Created September 7, 2015 04:02
A little script to enter pyenv mode.
#!/bin/bash
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
export PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h(python)\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
bash --noprofile -l
@fourdollars
fourdollars / wodim-iso.py
Last active August 29, 2015 14:24
A simple program to burn DVD ISO by wodim with the minimum write speed. For example: ./wodim-iso.py /dev/sr0 ubuntu.iso
#! /usr/bin/env python3
#
# Copyright (C) 2015 Canonical Limited
# Author: Shih-Yuan Lee (FourDollars) <sylee@canonical.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
@fourdollars
fourdollars / HowFastOfUbuntu.py
Created July 3, 2015 11:17
A simple fullscreen video player by clutter-gst.
#!/usr/bin/env python3
from gi.repository import Clutter, ClutterGst, Gdk
class VideoPlayer:
def __init__(self, filename):
stage_color = Clutter.Color.new(0, 0, 0, 0)
screen = Gdk.Screen.get_default()
monitor = screen.get_primary_monitor()