Skip to content

Instantly share code, notes, and snippets.

@lccxx
lccxx / recursive_to_loop.rb
Created November 2, 2011 07:02
F[0]=1; F[1]=1; F[n]=F[n div 2]+F[n div 3]+F[n div 5]+F[n div 7] with Ruby
def loop_f(n)
collect_div_2 = []
collect_div_3 = []
collect_div_5 = []
collect_div_7 = []
div_r = n
while true
div_r /= 2
if div_r == 0 || div_r == 1
@lccxx
lccxx / recursive_to_loop.c
Created November 3, 2011 04:01
F[0]=1; F[1]=1; F[n]=F[n div 2]+F[n div 3]+F[n div 5]+F[n div 7] with C
#include <stdio.h>
#include <stdlib.h>
#define true 1
#define false 0
typedef struct {
unsigned long long buff[65535];
int size;
} collection;
@lccxx
lccxx / progressbar.html
Created March 15, 2012 08:54
css3 animation progressbar
<!DOCTYPE html>
<html>
<style>
div.progressbar {
background-color: #6188F5; background-repeat: repeat-x;
background-position: 0 0; background-size: 16px 9px;
background-image: -webkit-linear-gradient(315deg,transparent,transparent 33%,
rgba(0, 0, 0, 0.12) 33%, rgba(0, 0, 0, 0.12) 66%, transparent 66%,
transparent);
background-image: -moz-linear-gradient(315deg,transparent,transparent 33%,
@lccxx
lccxx / testall.py
Created March 27, 2012 10:52
pyunit test all
#!/usr/bin/python2.6
# -*- coding: utf-8 -*-
import sys, os, re, unittest
test = re.compile("test\.py$", re.IGNORECASE)
def get_test_files(dir, files):
""" recursion search test module
Args: dir: search root directory, files: result container """
for file in os.listdir(dir):
@lccxx
lccxx / download_all_pic.sh
Created July 20, 2012 08:15
download all pic
#!/bin/bash
auth='--ntlm --user xxmu\xxyxy:1234567'
host="http://www.xxmu.edu.cn"
dir=$host"/tpxz/2012%E5%B1%8A%E6%9C%AC%E7%A7%91%E6%AF%95%E4%B8%9A%E7%94%9F%E6%AF%95%E4%B8%9A%E5%85%B8%E7%A4%BC%E7%85%A7%E7%89%87/"
function get_href {
grep -io 'href="[^"]*"' | sed -r 's/href="([^"]*)"/\1/i'
@lccxx
lccxx / step_1.sh
Created August 5, 2012 23:55
Linux From Scratch - Version 7.1, console history shell script
#!/bin/bash
function tip { echo -e '\E[37;44m'"\033[1m$1\033[0m"; }
set +h
umask 022
export LFS="/srv/lfs/6.6"
export LC_ALL=POSIX
export LFS_TGT=$(uname -m)-lfs-linux-gnu
export PATH=/tools/bin:/bin:/usr/bin
@lccxx
lccxx / PlagueInc.yml
Last active December 17, 2015 20:39
PlagueInc.yml
---
Type:
Bacteria: Most common cause of Plague. Unlimited potential
Virus: A rapidly mutating pathogen which is extremely hard to control
Fungus: Fungal spores struggle to travel long distances without special effort
Parasite: Parasitic lifestyle prevents DNA alteration from everyday infection
Prion: Slow, subtle and extremely complex pathogen hidden inside the brain
"Nano-Virus": Out of control, microscopic machine with a built in kill switch
"Bio-Weapon": Exceptionally lethal pathogen that kills everything it touches
"Neurax Worm": Manipulative organism that burrows into the brain
@lccxx
lccxx / obj2str.js
Created March 17, 2016 06:04
js obj with function stringify
function obj2str(obj) {
var fString = function(objj) {
if (!objj) return objj;
var newObj = Array.isArray(objj) ? [] : {}
Object.keys(objj).map(function(k) {
if (typeof(objj[k]) == "function") newObj[k] = objj[k].toString();
else if (typeof(objj[k]) == "object") newObj[k] = fString(objj[k]);
else newObj[k] = objj[k];
})
return newObj;
@lccxx
lccxx / lcs.rb
Created July 12, 2016 09:53
Longest common subsequence problem
x, y = "CATCGA", "GTACCGTCA"
table = [ ]
(0..x.length).each { table << row = [ ]; (0..y.length).each { row << 0 } }
x.chars.each_with_index { |xc, xi|
y.chars.each_with_index { |yc, yi|
pxv = table[xi][yi + 1]
pyv = table[xi + 1][yi]
pvg = pxv > pyv ? pxv : pyv
pvl = pxv <= pyv ? pxv : pyv
@lccxx
lccxx / telegram_math_battle.js
Created October 17, 2016 06:36
Telegram bot "Math Battle" cheat script
window.setInterval(function() { var vx = document.getElementById("task_x").innerText, op = { "+": "+", "–": "-", "×": "*", "/": "/" }[document.getElementById("task_op").innerText], vy = document.getElementById("task_y").innerText, res = document.getElementById("task_res").innerText, r_btn = document.getElementById("button_correct"), w_btn = document.getElementById("button_wrong"); console.log(vx, op, vy, res, r_btn, w_btn); if (eval(vx + op + vy) == res * 1) r_btn.click(); else w_btn.click() }, 500)