Skip to content

Instantly share code, notes, and snippets.

View sunnylost's full-sized avatar
💭
I may be slow to respond.

sunnylost sunnylost

💭
I may be slow to respond.
View GitHub Profile
class MyLogger
private_class_method :new
@@logger = nil
def MyLogger.create
@@logger = new unless @@logger
@@logger
end
end
=begin
@sunnylost
sunnylost / TCPL 2-3.c
Last active December 18, 2015 16:39
TCPL 习题集 第二章
//16 进制转 10 进制
#include <stdio.h>
int strlen(char[]);
int htoi(char[]);
int pow(int, int);
int main() {
char s[] = "1.00";
@sunnylost
sunnylost / 1-22.c
Created June 19, 2013 17:27
TCPL 习题集 第一章
//超过 80 个字符自动折行。
//折行位置为最近的一个空格,如果没有空格,则从连续文本中断开,加上连字符。
#define MAXLENGTH 80
void newline();
void printArray(char arr[], int pos);
int main(char args[]) {
newline();
@sunnylost
sunnylost / 3-2.c
Last active December 18, 2015 17:39
TCPL 习题集 第三章
//escape 与 unescape,针对 \n 与 \t 做转义或逆操作。
#include <stdio.h>
void escape(char[], char[]);
void unescape(char[], char[]);
int strlen(char[]);
int main() {
@sunnylost
sunnylost / 4-12.c
Last active December 18, 2015 19:00
TCPL 习题集 第四章
#include <stdio.h>
char s[100];
int i = 0;
void itoa(int);
void itoa(int d) {
int tmp;
if(d == 0) {
@sunnylost
sunnylost / 5-2.c
Last active December 18, 2015 22:39
TCPL 习题集 第五章
//部分程序来自于上一章节
//getfloat:将字符串转换成 float
#include <stdio.h>
#include <ctype.h>
#include "calc.h"
int getch(void);
void ungetch(int);
int getfloat(double *);
@sunnylost
sunnylost / tips.js
Last active December 21, 2015 16:18
// http://www.paulirish.com/2009/random-hex-color-code-snippets/#comment-931662323
(Math.random().toString(16) + '000000').slice(2, 8);
//=============================== Cursor's position =============================
var editable = document.getElementById('editable'),
selection, range;
// Populates selection and range variables
var captureSelection = function(e) {
@sunnylost
sunnylost / dabblet.css
Created October 18, 2013 16:17
The first commented line is your dabblet’s title
/**
* The first commented line is your dabblet’s title
*/
background: #f06;
background: linear-gradient(45deg, #f06, yellow);
min-height: 100%;
//http://codeforces.com/problemset/problem/1/B
var min = 64;
function convertNumToStr(num) {
console.log(num)
if(num <= 0) throw Error('Number must be greater than 0.');
var result = 27;
var remain;
@sunnylost
sunnylost / build.js
Created August 19, 2014 10:39
Build.js
var fs = require('fs'),
through = require('through2'),
uglify = require('uglify-js');
var BASE = './script-ss/',
DEST = './script-min/',
SPECIAL_TAG = '/*common*/';
var modules = [];