Skip to content

Instantly share code, notes, and snippets.

@yukioc
yukioc / lastlog.js
Created August 17, 2012 15:10
write time and comment to log file for recording a login or logout time.
var a=WScript.arguments;
var f=WScript.CreateObject("Scripting.FileSystemObject");
var d=(new Date()).toLocaleString();
var c=(a.length>0)?a(0):"";
var n=WScript.ScriptFullName.replace(/\.\w+/,".txt");
var t=f.OpenTextFile(n,8,true);
t.WriteLine( d+" "+c );
t.Close();
@yukioc
yukioc / montage.pl
Created May 6, 2012 11:33
combine 4 pictuers.
#!/usr/local/bin/perl
use strict;
use warnings;
use Image::Magick;
print <<USAGE if $#ARGV==-1;
Usage: montage.pl file..`
USAGE
my $img = new Image::Magick;
$img->Read(@ARGV);
my $mon=$img->Montage(geometry=>'160',tile=>'2x2');
@yukioc
yukioc / md5sum-1.c
Created March 18, 2012 02:10
md5 checksum of string
#include <stdio.h>
#include <openssl/md5.h>
int main(int argc,char *argv[]){
MD5_CTX c;
FILE *f;
unsigned char b[1024];
unsigned char md[MD5_LBLOCK];
size_t n;
int i;
if(argc!=2){
@yukioc
yukioc / jpn-calendar.html
Created February 25, 2012 14:22
a simple japanese calendar
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Japanese Calendar</title>
<!-- stylesheet -->
<style type="text/css">
<!--
body { font-size:smaller; }
em { font-style: normal; font-weight: bold; background-color: yellow; }
@yukioc
yukioc / pcre-eg.c
Created February 13, 2012 15:46
regex example using pcre.
#!/usr/bin/tcc -run -lpcre
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pcre.h>
int main(int argc,char*argv[]){
int ov[9],errofs;
char b[1024];
const char* err;
pcre *re=pcre_compile("Revision: (\\d+)",0,&err,&errofs,NULL);
@yukioc
yukioc / regex-eg.c
Created February 12, 2012 02:25
posix regex example code
#include <stdio.h>
#include <stdlib.h>
#include <regex.h>
int main(int argc,char*argv[]){
char b[1024],i=-1,n=0;
regex_t re;
regmatch_t m[9];
if(argc==1)return 1;
regcomp(&re,argv[1],REG_EXTENDED|REG_NEWLINE);
if(argc>2) n=atoi(argv[2]);
@yukioc
yukioc / twit-prof.html
Created January 3, 2012 06:43
get twitter user info and rss address.
<html>
<body>
<input type='text' id='screen_name'/>
<input type='submit' onclick='twit_rss_run();' />
<div id='view'></div>
<script>
function twit_rss_run(){
var name=document.getElementById('screen_name').value;
var v=document.getElementById('view');
var s=document.createElement('script');
@yukioc
yukioc / bblsort-eg.c
Created December 14, 2011 14:13
sort example
#include <stdio.h>
#include <stdlib.h> /* rand */
#include <assert.h>
int swp_calls=0;
void swap(int *s,int *d){
int t=*s;
*s=*d;
*d=t;
swp_calls++;
@yukioc
yukioc / arg.c
Created September 20, 2011 08:38
get command line options
/*
$ gcc arg.c
$ ./a.out -f -s 10 --longflag --longparam=20 aaa
option f
option s with value 10
option longflag
option longparam with value 20
last option aaa
*/
#include <stdio.h>
@yukioc
yukioc / fizzbuzz.c
Created September 18, 2011 16:41
fizz buzz
#include <stdio.h>
void main(){
int i;
for(i=1;i<100;i++){
if(printf("%s%s",
(i%3==0)?"Fizz":"",
(i%5==0)?"Buzz":"")==0){
printf("%d",i);
}
puts("");