Skip to content

Instantly share code, notes, and snippets.

@upsuper
upsuper / constants.py
Last active December 31, 2015 14:49
Constants
#!/usr/bin/env python
# - * - coding: UTF-8 - * -
class Constants(object):
__slots__ = ['_d']
def __init__(self, d):
self._d = d
for k, v in self._d.items():
if isinstance(v, dict):
@upsuper
upsuper / rbtree.hpp
Last active October 3, 2021 21:28
A Red-Black Tree implemented in C++ (need C++11)
#ifndef RBTREE_RBTREE_H_
#define RBTREE_RBTREE_H_
#include <cstddef>
#include <cassert>
#include <utility>
namespace upsuper {
namespace learning {
@upsuper
upsuper / progress_indicator.py
Created June 10, 2013 05:52
Graphic progress indicator in command line. It may only support OS X.
#!/usr/bin/python
# - * - coding: UTF-8 - * -
from sys import stdout
from time import sleep
from itertools import cycle
MOON = [u'\U0001F311', u'\U0001F312', u'\U0001F313', u'\U0001F314',
u'\U0001F315', u'\U0001F316', u'\U0001F317', u'\U0001F318']
@upsuper
upsuper / bgmrank.rb
Last active May 14, 2019 03:40
统计 Bangumi 上一个用户的收藏的评分分布情况,已移至 https://github.com/upsuper/bgmrank
#!/usr/bin/env ruby
require 'optparse'
require 'net/http'
CATEGORIES = [:anime, :book, :music, :game, :real]
STATES = [:wish, :collect, :do, :on_hold, :dropped]
progress = true
options = {
@upsuper
upsuper / gist:5351509
Created April 10, 2013 03:22
Simplify IP segments by removing redundant segments and merging adjacent segments.
# coding: UTF-8
import socket
import struct
def aton(addr):
return struct.unpack('!l', socket.inet_aton(addr))
def ntoa(addr):
return socket.inet_ntoa(struct.pack('!l', addr))
@upsuper
upsuper / gist:5069549
Last active December 14, 2015 10:09
Counting non-printable characters in .js and .css files.
class FileInfo
def initialize(name, data)
@name = name
@length = data.length
@space = data.each_char.inject(0) { |n, c|
n += case c
when '\t' then 8
when /\s/ then 1
else 0
end
diff -ur a/CPP/7zip/Archive/Zip/ZipItem.cpp b/CPP/7zip/Archive/Zip/ZipItem.cpp
--- a/CPP/7zip/Archive/Zip/ZipItem.cpp 2016-02-02 03:50:10.000000000 +1100
+++ b/CPP/7zip/Archive/Zip/ZipItem.cpp 2023-08-15 23:19:44.862769098 +1000
@@ -1,6 +1,7 @@
// Archive/ZipItem.cpp
#include "StdAfx.h"
+#include <iconv.h>
#include "../../../../C/CpuArch.h"
@upsuper
upsuper / mkramdisk
Created January 6, 2013 02:30
Script for OS X to create ramdisk & mount to a given place. This script is also enabled to resize the ramdisk it creates by mounting a new one and copying files into it.
#!/bin/zsh
INITIAL_SIZE=5
VOLUME_NAME='ramdisk'
MOUNTPOINT='/tmp/upsuper'
MOUNTPOINT_FILE='/tmp/ramdisk.mountpoint'
# find a non-existent initial mount point
mountpoint=$(mktemp -dt ramdisk)
# set ramdisk size
@upsuper
upsuper / corestatus.sh
Created December 28, 2012 04:43
Switch number of CPU cores in Linux
#!/bin/bash
cat /proc/cpuinfo | grep processor | wc -l
@upsuper
upsuper / af_alternate.c
Created October 12, 2012 16:27
Interesting Audio Filters for MPlayer
/*
* Copyright (C) 2012 Xidorn Quan <quanxunzhen@gmail.com>
*
* This file is part of MPlayer.
*
* MPlayer 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 2 of the License, or
* (at your option) any later version.
*