https://wiki.archlinux.org/api.php?action=feedcontributions&user=Bavardage&feedformat=atomArchWiki - User contributions [en]2024-03-28T19:25:33ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=71218User:Haxit/Kiloseconds2009-06-25T21:48:42Z<p>Bavardage: updated coloured curses python</p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Delphi ==<br />
program Kiloseconds;<br />
<br />
{$APPTYPE CONSOLE}<br />
<br />
uses<br />
SysUtils;<br />
<br />
var<br />
h,m,s,ms: word;<br />
begin<br />
DecodeTime(now, h, m, s, ms);<br />
Writeln('It is ' + FloatToStrF( (h*3600 + m*60 + s) / 1000, ffNumber, 7, 2) + ' kiloseconds.');<br />
end.<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
==Emacs Lisp==<br />
(require 'cl)<br />
<br />
(defun ks-from-time (seconds minutes hours)<br />
(/ (+ seconds (* minutes 60) (* hours 3600))1000.0))<br />
<br />
(defun ks-time ()<br />
(interactive)<br />
(message "It's %.3f ks" (apply 'ks-from-time (subseq (decode-time) 0 3))))<br />
<br />
(defun erc-cmd-KS ()<br />
(erc-send-message<br />
(format "It's %.3f ks" (apply 'ks-from-time (subseq (decode-time) 0 3)))))<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
io:format("It is ~w kiloseconds ~n", [(Hour * 3600 + Minutes * 60 + Seconds)/1000]).<br />
<br />
== Factor ==<br />
<br />
USING: accessors calendar kernel math prettyprint ;<br />
IN: kiloseconds<br />
<br />
: kiloseconds ( -- n )<br />
now [ hour>> 3600 * ] [ minute>> 60 * ]<br />
[ second>> ] tri + + 1000 /i ;<br />
<br />
: main ( -- )<br />
kiloseconds . ;<br />
<br />
MAIN: main<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
What about <tt>printf "%.2f" value</tt>?<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== LOLCODE (LOLPython) ==<br />
[http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html LOLPython here]<br />
<br />
IN MAI time GIMME localtime LIKE NOW<br />
TODAYS CAN HAZ NOW THING<br />
<br />
KILOSECONDS CAN HAZ EASTERBUNNY<br />
PILE CAN HAZ CHEEZBURGER<br />
<br />
KILOSECONDS GETZ ANOTHR 3600 OF THOSE TODAYS OWN tm_hour<br />
KILOSECONDS GETZ ANOTHR 60 OF THOSE TODAYS OWN tm_min<br />
KILOSECONDS GETZ ANOTHR PILE OF THOSE TODAYS OWN tm_sec<br />
<br />
VISIBLE "OMG IT'S" AND KILOSECONDS SMASHES INTO 1000.0 AND "KILOSECONDS"<br />
<br />
== Lua ==<br />
This version displays the time once<br />
print("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Mathematica ==<br />
Drop[DateList[],3].{3600,60,1}/1000<br />
<br />
== MatLab ==<br />
function ks = kiloseconds();<br />
% make a clock<br />
c = clock;<br />
% get hour<br />
hour = c(4);<br />
% get minutes <br />
min = c(5);<br />
% get seconds<br />
sec = c(6);<br />
ks = (hour * (min*60) * sec)/ 1000;<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks/1000 . " kiloseconds\n");<br />
?><br />
<br />
== PLT Scheme == <br />
(let* ([date-struct (seconds->date (current-seconds))]<br />
[seconds (date-second date-struct)]<br />
[minutes (date-minute date-struct)]<br />
[hours (date-hour date-struct)])<br />
(display (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Prolog (SWI-Prolog) ==<br />
<pre><br />
#!/usr/bin/env swipl -g kiloseconds -s<br />
kiloseconds :- <br />
get_time(T), <br />
stamp_date_time(T,date(_,_,_,H,M,S,_,_,_),'local'), <br />
format('It is: ~f kiloseconds.~n',[(H*3600+M*60+S)/1000]).<br />
</pre><br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Python Ncurses ==<br />
With fancy colours and everything<br />
./curses_clock.py -h for usage<br />
You have been warned<br />
<pre><br />
#!/usr/bin/env python<br />
<br />
import curses<br />
import signal<br />
import traceback<br />
import time<br />
<br />
import getopt, sys<br />
<br />
DIGIT_WIDTH = 5<br />
DIGIT_HEIGHT = 5<br />
DIGIT_SPACING = 2<br />
<br />
'''<br />
_0_0_._0_0_0_<br />
'''<br />
<br />
width = 7*DIGIT_SPACING + 6*DIGIT_WIDTH <br />
height = 2*DIGIT_SPACING + DIGIT_HEIGHT<br />
<br />
<br />
# numbers, list of coords in (y,x)<br />
<br />
digits = [<br />
[<br />
"#####",<br />
"# #",<br />
"# #",<br />
"# #",<br />
"#####"<br />
],<br />
[<br />
" # ",<br />
" ## ",<br />
" # ",<br />
" # ",<br />
" ### ",<br />
],<br />
[<br />
"#####",<br />
" #",<br />
"#####",<br />
"# ",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
" #",<br />
" ####",<br />
" #",<br />
"#####",<br />
],<br />
[<br />
"# #",<br />
"# #",<br />
"#####",<br />
" #",<br />
" #",<br />
],<br />
[<br />
"#####",<br />
"# ",<br />
"#####",<br />
" #",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
"# ",<br />
"#####",<br />
"# #",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
" #",<br />
" #",<br />
" #",<br />
" #",<br />
],<br />
[<br />
"#####",<br />
"# #",<br />
"#####",<br />
"# #",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
"# #",<br />
"#####",<br />
" #",<br />
" #",<br />
],<br />
[<br />
"",<br />
"",<br />
"",<br />
"",<br />
" # ",<br />
],<br />
]<br />
<br />
def draw_digit(win, digit, y, x):<br />
sections = digits[digit]<br />
position = 0<br />
for section in sections:<br />
xpos = x<br />
for char in section:<br />
if char == ' ':<br />
win.addstr(position+y, xpos, ' ', curses.color_pair(0))<br />
else:<br />
win.addstr(position+y, xpos, ' ', curses.color_pair(1))<br />
xpos += 1<br />
position += 1<br />
<br />
def draw_time(win, digits):<br />
h,w = win.getmaxyx()<br />
x_pos = (w - width) / 2<br />
y_pos = (h - height) / 2<br />
x_pos += DIGIT_SPACING<br />
y_pos += 1<br />
digits.insert(2, 10) #add in the point<br />
for d in digits:<br />
draw_digit(win, d, y_pos, x_pos)<br />
x_pos += (DIGIT_SPACING + DIGIT_WIDTH)<br />
<br />
def tick(win):<br />
tm = time.localtime()<br />
t = ks = tm.tm_hour*3600 + tm.tm_min*60 + tm.tm_sec<br />
a = ks/10000; ks -= a*10000<br />
b = ks/1000; ks -= b*1000<br />
c = ks/100; ks -= c*100<br />
d = ks/10; ks -= d*10<br />
e = ks<br />
draw_time(win, [a,b,c,d,e])<br />
return t<br />
<br />
def draw_dots(win):<br />
h,w = win.getmaxyx()<br />
x_pos = (w - width) / 2<br />
y_pos = (h - height) / 2<br />
win.hline(y_pos,x_pos,curses.ACS_BULLET, width, curses.color_pair(2))<br />
win.hline(y_pos+DIGIT_HEIGHT+1,x_pos,curses.ACS_BULLET, width, curses.color_pair(2))<br />
win.vline(y_pos+1,x_pos,curses.ACS_BULLET, DIGIT_HEIGHT, curses.color_pair(2))<br />
win.vline(y_pos+1,x_pos+width-1,curses.ACS_BULLET, DIGIT_HEIGHT, curses.color_pair(2))<br />
<br />
<br />
def init_screen():<br />
screen = curses.initscr()<br />
curses.noecho()<br />
curses.cbreak()<br />
screen.clear()<br />
<br />
def main(screen, fg, bg):<br />
curses.curs_set(0) #hide cursor<br />
screen.nodelay(1) # don't wait for input<br />
<br />
curses.use_default_colors()<br />
<br />
curses.init_pair(1, fg, fg)<br />
curses.init_pair(2, fg, bg)<br />
<br />
screen.bkgd(' ', curses.color_pair(2))<br />
<br />
def screen_resize(*args):<br />
while 1:<br />
try: curses.endwin(); break<br />
except: time.sleep(1)<br />
screen.erase()<br />
draw_dots(screen)<br />
screen.refresh()<br />
<br />
signal.signal(signal.SIGWINCH, screen_resize)<br />
<br />
draw_dots(screen)<br />
<br />
<br />
t = None<br />
while True:<br />
newtime = tick(screen)<br />
if t != newtime:<br />
screen.refresh()<br />
t = newtime<br />
<br />
c = screen.getch()<br />
if c == ord('q'):<br />
break<br />
<br />
time.sleep(0.5)<br />
<br />
<br />
def usage():<br />
print '''curses_clock.py [OPTION]<br />
<br />
-h, --help displays this help<br />
-f, --fg=COLORCODE sets the foreground color to COLORCODE<br />
-b, --bg=COLORCODE sets the background color to COLORCODE<br />
<br />
<br />
Color codes available:<br />
default term fg/bg -1<br />
black 0<br />
red 1<br />
green 2<br />
yellow 3<br />
blue 4<br />
magenta 5<br />
cyan 6<br />
white 7<br />
'''<br />
<br />
<br />
<br />
if __name__ == '__main__':<br />
bg = 0<br />
fg = 7<br />
<br />
def do_color(arg):<br />
try:<br />
color = int(arg)<br />
except:<br />
color = -1<br />
if not -1 <= color <= 7:<br />
print "Color code not in correct range"<br />
usage()<br />
sys.exit(2)<br />
else:<br />
return color<br />
<br />
<br />
try:<br />
opts, args = getopt.getopt(sys.argv[1:], "hf:b:", ["help", "fg=", "bg="])<br />
except getopt.GetoptError:<br />
usage()<br />
sys.exit(2)<br />
<br />
for opt, arg in opts:<br />
if opt in ("-h", "--help"):<br />
usage()<br />
sys.exit()<br />
elif opt in ("-f", "--fg"):<br />
fg = do_color(arg)<br />
elif opt in ("-b", "--bg"):<br />
bg = do_color(arg)<br />
<br />
<br />
curses.wrapper(main, fg, bg)<br />
</pre><br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Scala ==<br />
Could be done shorter, but this demonstrates some nice Scala features.<br />
import java.util.Calendar<br />
<br />
object Kilosecond {<br />
private implicit def enrichCalendar(c: Calendar) = new CalendarWrapper(c)<br />
<br />
def main(args: Array[String]) = {<br />
val c = Calendar.getInstance<br />
<br />
println("Kiloseconds: " + c.kiloseconds)<br />
}<br />
<br />
private class CalendarWrapper(c: Calendar) {<br />
def kiloseconds = {<br />
val hours = c.get(Calendar.HOUR_OF_DAY)<br />
val minutes = c.get(Calendar.MINUTE)<br />
val seconds = c.get(Calendar.SECOND)<br />
<br />
(hours * 3600 + minutes * 60 + seconds) / 1000.0<br />
}<br />
}<br />
}<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'<br />
<br />
== TCL ==<br />
puts "It's [expr [clock format [clock seconds] -format {(%k*3600+%M.0*60+%S.0)/1000}]] kiloseconds"<br />
<br />
== Weechat Plugin ==<br />
Requires weechat version 0.3.0+<br />
[http://weechat.flashtux.org/dev/scripts/kiloseconds.py kiloseconds.py]<br />
<br />
== IRSSI Plugin ==<br />
#!/usr/bin/perl<br />
<br />
use vars qw($VERSION %IRSSI);<br />
use Irssi;<br />
use strict;<br />
$VERSION = '0.10';<br />
%IRSSI = (<br />
authors => 'Ben Duffield',<br />
contact => 'jebavarde AT gmail DOT com',<br />
name => 'kiloseconds',<br />
description => 'Reports the time in kiloseconds',<br />
license => 'GPL',<br />
url => 'http://wiki.archlinux.org/index.php/Kiloseconds',<br />
changed => 'no idea',<br />
); <br />
<br />
<br />
sub cmd_kiloseconds {<br />
my ($data, $server, $witem) = @_;<br />
my $output;<br />
my $ks;<br />
my $s;<br />
my $m; <br />
my $h;<br />
<br />
($s,$m,$h) = localtime();<br />
$ks = ($h*3600+$m*60+$s)/1000; <br />
<br />
$output = sprintf("Current time: %.3f kiloseconds", $ks);<br />
<br />
<br />
if ($output) {<br />
if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) {<br />
$witem->command("MSG ".$witem->{name}." $output");<br />
}<br />
else {<br />
Irssi::print("This is not a channel/query window :b");<br />
}<br />
}<br />
}<br />
<br />
Irssi::command_bind('kiloseconds', 'cmd_kiloseconds');<br />
<br />
== Oracle SQL ==<br />
select ((to_char(sysdate,'HH')*60*60)+(to_char(sysdate,'MM')*60)+(to_char(sysdate,'SS')))/1000 <br />
as "Kiloseconds" from dual</div>Bavardagehttps://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=71214User:Haxit/Kiloseconds2009-06-25T20:58:07Z<p>Bavardage: updated curses python</p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Delphi ==<br />
program Kiloseconds;<br />
<br />
{$APPTYPE CONSOLE}<br />
<br />
uses<br />
SysUtils;<br />
<br />
var<br />
h,m,s,ms: word;<br />
begin<br />
DecodeTime(now, h, m, s, ms);<br />
Writeln('It is ' + FloatToStrF( (h*3600 + m*60 + s) / 1000, ffNumber, 7, 2) + ' kiloseconds.');<br />
end.<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
==Emacs Lisp==<br />
(require 'cl)<br />
<br />
(defun ks-from-time (seconds minutes hours)<br />
(/ (+ seconds (* minutes 60) (* hours 3600))1000.0))<br />
<br />
(defun ks-time ()<br />
(interactive)<br />
(message "It's %.3f ks" (apply 'ks-from-time (subseq (decode-time) 0 3))))<br />
<br />
(defun erc-cmd-KS ()<br />
(erc-send-message<br />
(format "It's %.3f ks" (apply 'ks-from-time (subseq (decode-time) 0 3)))))<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
io:format("It is ~w kiloseconds ~n", [(Hour * 3600 + Minutes * 60 + Seconds)/1000]).<br />
<br />
== Factor ==<br />
<br />
USING: accessors calendar kernel math prettyprint ;<br />
IN: kiloseconds<br />
<br />
: kiloseconds ( -- n )<br />
now [ hour>> 3600 * ] [ minute>> 60 * ]<br />
[ second>> ] tri + + 1000 /i ;<br />
<br />
: main ( -- )<br />
kiloseconds . ;<br />
<br />
MAIN: main<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
What about <tt>printf "%.2f" value</tt>?<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== LOLCODE (LOLPython) ==<br />
[http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html LOLPython here]<br />
<br />
IN MAI time GIMME localtime LIKE NOW<br />
TODAYS CAN HAZ NOW THING<br />
<br />
KILOSECONDS CAN HAZ EASTERBUNNY<br />
PILE CAN HAZ CHEEZBURGER<br />
<br />
KILOSECONDS GETZ ANOTHR 3600 OF THOSE TODAYS OWN tm_hour<br />
KILOSECONDS GETZ ANOTHR 60 OF THOSE TODAYS OWN tm_min<br />
KILOSECONDS GETZ ANOTHR PILE OF THOSE TODAYS OWN tm_sec<br />
<br />
VISIBLE "OMG IT'S" AND KILOSECONDS SMASHES INTO 1000.0 AND "KILOSECONDS"<br />
<br />
== Lua ==<br />
This version displays the time once<br />
print("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Mathematica ==<br />
Drop[DateList[],3].{3600,60,1}/1000<br />
<br />
== MatLab ==<br />
function ks = kiloseconds();<br />
% make a clock<br />
c = clock;<br />
% get hour<br />
hour = c(4);<br />
% get minutes <br />
min = c(5);<br />
% get seconds<br />
sec = c(6);<br />
ks = (hour * (min*60) * sec)/ 1000;<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks/1000 . " kiloseconds\n");<br />
?><br />
<br />
== PLT Scheme == <br />
(let* ([date-struct (seconds->date (current-seconds))]<br />
[seconds (date-second date-struct)]<br />
[minutes (date-minute date-struct)]<br />
[hours (date-hour date-struct)])<br />
(display (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Prolog (SWI-Prolog) ==<br />
<pre><br />
#!/usr/bin/env swipl -g kiloseconds -s<br />
kiloseconds :- <br />
get_time(T), <br />
stamp_date_time(T,date(_,_,_,H,M,S,_,_,_),'local'), <br />
format('It is: ~f kiloseconds.~n',[(H*3600+M*60+S)/1000]).<br />
</pre><br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Python Ncurses ==<br />
Very messy, second version, kinda ugly.<br />
You have been warned<br />
<pre><br />
<br />
<br />
#!/usr/bin/env python<br />
<br />
import curses<br />
import signal<br />
import traceback<br />
import time<br />
<br />
DIGIT_WIDTH = 5<br />
DIGIT_HEIGHT = 5<br />
DIGIT_SPACING = 2<br />
<br />
'''<br />
_0_0_._0_0_0_<br />
'''<br />
<br />
width = 7*DIGIT_SPACING + 6*DIGIT_WIDTH <br />
height = 2*DIGIT_SPACING + DIGIT_HEIGHT<br />
<br />
<br />
# numbers, list of coords in (y,x)<br />
<br />
digits = [<br />
[<br />
"#####",<br />
"# #",<br />
"# #",<br />
"# #",<br />
"#####"<br />
],<br />
[<br />
" # ",<br />
" ## ",<br />
" # ",<br />
" # ",<br />
" ### ",<br />
],<br />
[<br />
"#####",<br />
" #",<br />
"#####",<br />
"# ",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
" #",<br />
" ####",<br />
" #",<br />
"#####",<br />
],<br />
[<br />
"# #",<br />
"# #",<br />
"#####",<br />
" #",<br />
" #",<br />
],<br />
[<br />
"#####",<br />
"# ",<br />
"#####",<br />
" #",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
"# ",<br />
"#####",<br />
"# #",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
" #",<br />
" #",<br />
" #",<br />
" #",<br />
],<br />
[<br />
"#####",<br />
"# #",<br />
"#####",<br />
"# #",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
"# #",<br />
"#####",<br />
" #",<br />
" #",<br />
],<br />
[<br />
"",<br />
"",<br />
"",<br />
"",<br />
" # ",<br />
],<br />
]<br />
<br />
def draw_digit(win, digit, y, x):<br />
sections = digits[digit]<br />
position = 0<br />
for section in sections:<br />
xpos = x<br />
for char in section:<br />
if char == ' ':<br />
win.addstr(position+y, xpos, ' ', curses.color_pair(0))<br />
else:<br />
win.addstr(position+y, xpos, ' ', curses.color_pair(1))<br />
xpos += 1<br />
position += 1<br />
<br />
def draw_time(win, digits):<br />
h,w = win.getmaxyx()<br />
x_pos = (w - width) / 2<br />
y_pos = (h - height) / 2<br />
x_pos += DIGIT_SPACING<br />
y_pos += 1<br />
digits.insert(2, 10) #add in the point<br />
for d in digits:<br />
draw_digit(win, d, y_pos, x_pos)<br />
x_pos += (DIGIT_SPACING + DIGIT_WIDTH)<br />
<br />
def tick(win):<br />
tm = time.localtime()<br />
t = ks = tm.tm_hour*3600 + tm.tm_min*60 + tm.tm_sec<br />
a = ks/10000; ks -= a*10000<br />
b = ks/1000; ks -= b*1000<br />
c = ks/100; ks -= c*100<br />
d = ks/10; ks -= d*10<br />
e = ks<br />
draw_time(win, [a,b,c,d,e])<br />
return t<br />
<br />
def draw_dots(win):<br />
h,w = win.getmaxyx()<br />
x_pos = (w - width) / 2<br />
y_pos = (h - height) / 2<br />
win.hline(y_pos,x_pos,curses.ACS_BULLET, width)<br />
win.hline(y_pos+DIGIT_HEIGHT+1,x_pos,curses.ACS_BULLET, width)<br />
win.vline(y_pos+1,x_pos,curses.ACS_BULLET, DIGIT_HEIGHT)<br />
win.vline(y_pos+1,x_pos+width-1,curses.ACS_BULLET, DIGIT_HEIGHT)<br />
<br />
<br />
def init_screen():<br />
screen = curses.initscr()<br />
curses.noecho()<br />
curses.cbreak()<br />
screen.clear()<br />
<br />
def main(screen):<br />
curses.curs_set(0) #hide cursor<br />
screen.nodelay(1) # don't wait for input<br />
curses.init_pair(1, curses.COLOR_RED, curses.COLOR_WHITE)<br />
<br />
def screen_resize(*args):<br />
while 1:<br />
try: curses.endwin(); break<br />
except: time.sleep(1)<br />
screen.erase()<br />
draw_dots(screen)<br />
screen.refresh()<br />
<br />
signal.signal(signal.SIGWINCH, screen_resize)<br />
<br />
draw_dots(screen)<br />
<br />
<br />
t = None<br />
while True:<br />
newtime = tick(screen)<br />
if t != newtime:<br />
screen.refresh()<br />
t = newtime<br />
<br />
c = screen.getch()<br />
if c == ord('q'):<br />
break<br />
<br />
time.sleep(0.5)<br />
<br />
if __name__ == '__main__':<br />
curses.wrapper(main)<br />
</pre><br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Scala ==<br />
Could be done shorter, but this demonstrates some nice Scala features.<br />
import java.util.Calendar<br />
<br />
object Kilosecond {<br />
private implicit def enrichCalendar(c: Calendar) = new CalendarWrapper(c)<br />
<br />
def main(args: Array[String]) = {<br />
val c = Calendar.getInstance<br />
<br />
println("Kiloseconds: " + c.kiloseconds)<br />
}<br />
<br />
private class CalendarWrapper(c: Calendar) {<br />
def kiloseconds = {<br />
val hours = c.get(Calendar.HOUR_OF_DAY)<br />
val minutes = c.get(Calendar.MINUTE)<br />
val seconds = c.get(Calendar.SECOND)<br />
<br />
(hours * 3600 + minutes * 60 + seconds) / 1000.0<br />
}<br />
}<br />
}<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'<br />
<br />
== TCL ==<br />
puts "It's [expr [clock format [clock seconds] -format {(%k*3600+%M.0*60+%S.0)/1000}]] kiloseconds"<br />
<br />
== Weechat Plugin ==<br />
Requires weechat version 0.3.0+<br />
[http://weechat.flashtux.org/dev/scripts/kiloseconds.py kiloseconds.py]<br />
<br />
== IRSSI Plugin ==<br />
#!/usr/bin/perl<br />
<br />
use vars qw($VERSION %IRSSI);<br />
use Irssi;<br />
use strict;<br />
$VERSION = '0.10';<br />
%IRSSI = (<br />
authors => 'Ben Duffield',<br />
contact => 'jebavarde AT gmail DOT com',<br />
name => 'kiloseconds',<br />
description => 'Reports the time in kiloseconds',<br />
license => 'GPL',<br />
url => 'http://wiki.archlinux.org/index.php/Kiloseconds',<br />
changed => 'no idea',<br />
); <br />
<br />
<br />
sub cmd_kiloseconds {<br />
my ($data, $server, $witem) = @_;<br />
my $output;<br />
my $ks;<br />
my $s;<br />
my $m; <br />
my $h;<br />
<br />
($s,$m,$h) = localtime();<br />
$ks = ($h*3600+$m*60+$s)/1000; <br />
<br />
$output = sprintf("Current time: %.3f kiloseconds", $ks);<br />
<br />
<br />
if ($output) {<br />
if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) {<br />
$witem->command("MSG ".$witem->{name}." $output");<br />
}<br />
else {<br />
Irssi::print("This is not a channel/query window :b");<br />
}<br />
}<br />
}<br />
<br />
Irssi::command_bind('kiloseconds', 'cmd_kiloseconds');<br />
<br />
== Oracle SQL ==<br />
select ((to_char(sysdate,'HH')*60*60)+(to_char(sysdate,'MM')*60)+(to_char(sysdate,'SS')))/1000 <br />
as "Kiloseconds" from dual</div>Bavardagehttps://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=70861User:Haxit/Kiloseconds2009-06-19T22:25:45Z<p>Bavardage: ncurses</p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Delphi ==<br />
program Kiloseconds;<br />
<br />
{$APPTYPE CONSOLE}<br />
<br />
uses<br />
SysUtils;<br />
<br />
var<br />
h,m,s,ms: word;<br />
begin<br />
DecodeTime(now, h, m, s, ms);<br />
Writeln('It is ' + FloatToStrF( (h*3600 + m*60 + s) / 1000, ffNumber, 7, 2) + ' kiloseconds.');<br />
end.<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
(Hour * 3600 + Minutes * 60 + Seconds)/1000.<br />
<br />
== Factor ==<br />
<br />
USING: accessors calendar kernel math prettyprint ;<br />
IN: kiloseconds<br />
<br />
: kiloseconds ( -- n )<br />
now [ hour>> 3600 * ] [ minute>> 60 * ]<br />
[ second>> ] tri + + 1000 /i ;<br />
<br />
: main ( -- )<br />
kiloseconds . ;<br />
<br />
MAIN: main<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
What about <tt>printf "%.2f" value</tt>?<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== LOLCODE (LOLPython) ==<br />
[http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html LOLPython here]<br />
<br />
IN MAI time GIMME localtime LIKE NOW<br />
TODAYS CAN HAZ NOW THING<br />
<br />
KILOSECONDS CAN HAZ EASTERBUNNY<br />
PILE CAN HAZ CHEEZBURGER<br />
<br />
KILOSECONDS GETZ ANOTHR 3600 OF THOSE TODAYS OWN tm_hour<br />
KILOSECONDS GETZ ANOTHR 60 OF THOSE TODAYS OWN tm_min<br />
KILOSECONDS GETZ ANOTHR PILE OF THOSE TODAYS OWN tm_sec<br />
<br />
VISIBLE "OMG IT'S" AND KILOSECONDS SMASHES INTO 1000.0 AND "KILOSECONDS"<br />
<br />
== Lua ==<br />
This version displays the time once<br />
io.write("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds\n")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks/1000 . " kiloseconds\n");<br />
?><br />
<br />
== PLT Scheme == <br />
(let* ([date-struct (seconds->date (current-seconds))]<br />
[seconds (date-second date-struct)]<br />
[minutes (date-minute date-struct)]<br />
[hours (date-hour date-struct)])<br />
(display (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Python Ncurses ==<br />
Very messy, first version, kinda ugly.<br />
You have been warned<br />
<pre><br />
#!/usr/bin/env python<br />
<br />
import curses<br />
import traceback<br />
import time<br />
<br />
DIGIT_WIDTH = 5<br />
DIGIT_HEIGHT = 5<br />
DIGIT_SPACING = 2<br />
POINT_SPACING = 0<br />
POINT_WIDTH = 5<br />
<br />
'''<br />
_0_0_._0_0_0_<br />
'''<br />
<br />
width = 5*DIGIT_SPACING + 5*DIGIT_WIDTH + 2*POINT_SPACING + POINT_WIDTH<br />
height = 2*DIGIT_SPACING + DIGIT_HEIGHT<br />
<br />
<br />
# numbers, list of coords in (y,x)<br />
<br />
digits = [<br />
[<br />
"#####",<br />
"# #",<br />
"# #",<br />
"# #",<br />
"#####"<br />
],<br />
[<br />
" #",<br />
" ##",<br />
" #",<br />
" #",<br />
" ###",<br />
],<br />
[<br />
"#####",<br />
" #",<br />
"#####",<br />
"#",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
" #",<br />
" ####",<br />
" #",<br />
"#####",<br />
],<br />
[<br />
"# #",<br />
"# #",<br />
"#####",<br />
" #",<br />
" #",<br />
],<br />
[<br />
"#####",<br />
"#",<br />
"#####",<br />
" #",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
"#",<br />
"#####",<br />
"# #",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
" #",<br />
" #",<br />
" #",<br />
" #",<br />
],<br />
[<br />
"#####",<br />
"# #",<br />
"#####",<br />
"# #",<br />
"#####",<br />
],<br />
[<br />
"#####",<br />
"# #",<br />
"#####",<br />
" #",<br />
" #",<br />
],<br />
[<br />
"",<br />
"",<br />
"",<br />
" ###",<br />
" ###",<br />
],<br />
]<br />
<br />
def draw_digit(win, digit, y, x):<br />
sections = digits[digit]<br />
position = 0<br />
for section in sections:<br />
win.addstr(position+y, x, section)<br />
position += 1<br />
<br />
def draw_time(win, digits):<br />
x_pos = DIGIT_SPACING<br />
y_pos = 1<br />
digits.insert(2, 10) #add in the point<br />
for d in digits:<br />
draw_digit(win, d, y_pos, x_pos)<br />
x_pos += (DIGIT_SPACING + DIGIT_WIDTH)<br />
<br />
def tick(win):<br />
tm = time.localtime()<br />
t = ks = tm.tm_hour*3600 + tm.tm_min*60 + tm.tm_sec<br />
a = ks/10000; ks -= a*10000<br />
b = ks/1000; ks -= b*1000<br />
c = ks/100; ks -= c*100<br />
d = ks/10; ks -= d*10<br />
e = ks<br />
draw_time(win, [a,b,c,d,e])<br />
return t<br />
<br />
<br />
def init_screen():<br />
screen = curses.initscr()<br />
curses.noecho()<br />
curses.cbreak()<br />
screen.clear()<br />
<br />
def restore_screen():<br />
curses.nocbreak()<br />
curses.echo()<br />
curses.endwin()<br />
print "screen restored"<br />
<br />
def main():<br />
screen = curses.initscr()<br />
curses.noecho()<br />
curses.cbreak()<br />
screen.clear()<br />
<br />
draw_time(screen, [0,1,2,1,2])<br />
<br />
t = None<br />
screen.hline(0,0,curses.ACS_BULLET, width)<br />
while True:<br />
screen.clear()<br />
newtime = tick(screen)<br />
if t != newtime:<br />
screen.refresh()<br />
t = newtime<br />
time.sleep(0.5)<br />
<br />
if __name__ == '__main__':<br />
try:<br />
main()<br />
# tick(None)<br />
finally:<br />
#pass <br />
restore_screen()<br />
<br />
<br />
<br />
<br />
<br />
<br />
</pre><br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Scala ==<br />
Could be done shorter, but this demonstrates some nice Scala features.<br />
import java.util.Calendar<br />
<br />
object Kilosecond {<br />
private implicit def enrichCalendar(c: Calendar) = new CalendarWrapper(c)<br />
<br />
def main(args: Array[String]) = {<br />
val c = Calendar.getInstance<br />
<br />
println("Kiloseconds: " + c.kiloseconds)<br />
}<br />
<br />
private class CalendarWrapper(c: Calendar) {<br />
def kiloseconds = {<br />
val hours = c.get(Calendar.HOUR_OF_DAY)<br />
val minutes = c.get(Calendar.MINUTE)<br />
val seconds = c.get(Calendar.SECOND)<br />
<br />
(hours * 3600 + minutes * 60 + seconds) / 1000.0<br />
}<br />
}<br />
}<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'<br />
<br />
== Weechat Plugin ==<br />
Requires weechat version 0.3.0+<br />
[http://weechat.flashtux.org/dev/scripts/kiloseconds.py kiloseconds.py]<br />
<br />
== IRSSI Plugin ==<br />
#!/usr/bin/perl<br />
<br />
use vars qw($VERSION %IRSSI);<br />
use Irssi;<br />
use strict;<br />
$VERSION = '0.10';<br />
%IRSSI = (<br />
authors => 'Ben Duffield',<br />
contact => 'jebavarde AT gmail DOT com',<br />
name => 'kiloseconds',<br />
description => 'Reports the time in kiloseconds',<br />
license => 'GPL',<br />
url => 'http://wiki.archlinux.org/index.php/Kiloseconds',<br />
changed => 'no idea',<br />
); <br />
<br />
<br />
sub cmd_kiloseconds {<br />
my ($data, $server, $witem) = @_;<br />
my $output;<br />
my $ks;<br />
my $s;<br />
my $m; <br />
my $h;<br />
<br />
($s,$m,$h) = localtime();<br />
$ks = ($h*3600+$m*60+$s)/1000; <br />
<br />
$output = sprintf("Current time: %.3f kiloseconds", $ks);<br />
<br />
<br />
if ($output) {<br />
if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) {<br />
$witem->command("MSG ".$witem->{name}." $output");<br />
}<br />
else {<br />
Irssi::print("This is not a channel/query window :b");<br />
}<br />
}<br />
}<br />
<br />
Irssi::command_bind('kiloseconds', 'cmd_kiloseconds');<br />
<br />
== Oracle SQL ==<br />
select ((to_char(sysdate,'HH')*60*60)+(to_char(sysdate,'MM')*60)+(to_char(sysdate,'SS')))/1000 <br />
as "Kiloseconds" from dual</div>Bavardagehttps://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=70816User:Haxit/Kiloseconds2009-06-18T19:40:06Z<p>Bavardage: /* IRSSI Plugin */</p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
(Hour * 3600 + Minutes * 60 + Seconds)/1000.<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== LOLCODE (LOLPython) ==<br />
[http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html LOLPython here]<br />
<br />
IN MAI time GIMME localtime LIKE NOW<br />
TODAYS CAN HAZ NOW THING<br />
<br />
KILOSECONDS CAN HAZ EASTERBUNNY<br />
PILE CAN HAZ CHEEZBURGER<br />
<br />
KILOSECONDS GETZ ANOTHR 3600 OF THOSE TODAYS OWN tm_hour<br />
KILOSECONDS GETZ ANOTHR 60 OF THOSE TODAYS OWN tm_min<br />
KILOSECONDS GETZ ANOTHR PILE OF THOSE TODAYS OWN tm_sec<br />
<br />
VISIBLE "OMG IT'S" AND KILOSECONDS SMASHES INTO 1000.0 AND "KILOSECONDS"<br />
<br />
== Lua ==<br />
This version displays the time once<br />
io.write("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds\n")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks/1000 . " kiloseconds\n");<br />
?><br />
<br />
== PLT Scheme == <br />
(let* ([date-struct (seconds->date (current-seconds))]<br />
[seconds (date-second date-struct)]<br />
[minutes (date-minute date-struct)]<br />
[hours (date-hour date-struct)])<br />
(display (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Scala ==<br />
Could be done shorter, but this demonstrates some nice Scala features.<br />
import java.util.Calendar<br />
<br />
object Kilosecond {<br />
private implicit def enrichCalendar(c: Calendar) = new CalendarWrapper(c)<br />
<br />
def main(args: Array[String]) = {<br />
val c = Calendar.getInstance<br />
<br />
println("Kiloseconds: " + c.kiloseconds)<br />
}<br />
<br />
private class CalendarWrapper(c: Calendar) {<br />
def kiloseconds = {<br />
val hours = c.get(Calendar.HOUR_OF_DAY)<br />
val minutes = c.get(Calendar.MINUTE)<br />
val seconds = c.get(Calendar.SECOND)<br />
<br />
(hours * 3600 + minutes * 60 + seconds) / 1000.0<br />
}<br />
}<br />
}<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'<br />
<br />
== Weechat Plugin ==<br />
Requires weechat version 0.3.0+<br />
[http://weechat.flashtux.org/dev/scripts/kiloseconds.py kiloseconds.py]<br />
<br />
== IRSSI Plugin ==<br />
#!/usr/bin/perl<br />
<br />
use vars qw($VERSION %IRSSI);<br />
use Irssi;<br />
use strict;<br />
$VERSION = '0.10';<br />
%IRSSI = (<br />
authors => 'Ben Duffield',<br />
contact => 'jebavarde AT gmail DOT com',<br />
name => 'kiloseconds',<br />
description => 'Reports the time in kiloseconds',<br />
license => 'GPL',<br />
url => 'http://wiki.archlinux.org/index.php/Kiloseconds',<br />
changed => 'no idea',<br />
); <br />
<br />
<br />
sub cmd_kiloseconds {<br />
my ($data, $server, $witem) = @_;<br />
my $output;<br />
my $ks;<br />
my $s;<br />
my $m; <br />
my $h;<br />
<br />
($s,$m,$h) = localtime();<br />
$ks = ($h*3600+$m*60+$s)/1000; <br />
<br />
$output = sprintf("Current time: %.3f kiloseconds", $ks);<br />
<br />
<br />
if ($output) {<br />
if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) {<br />
$witem->command("MSG ".$witem->{name}." $output");<br />
}<br />
else {<br />
Irssi::print("This is not a channel/query window :b");<br />
}<br />
}<br />
}<br />
<br />
Irssi::command_bind('kiloseconds', 'cmd_kiloseconds');</div>Bavardagehttps://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=70815User:Haxit/Kiloseconds2009-06-18T19:39:47Z<p>Bavardage: </p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
(Hour * 3600 + Minutes * 60 + Seconds)/1000.<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== LOLCODE (LOLPython) ==<br />
[http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html LOLPython here]<br />
<br />
IN MAI time GIMME localtime LIKE NOW<br />
TODAYS CAN HAZ NOW THING<br />
<br />
KILOSECONDS CAN HAZ EASTERBUNNY<br />
PILE CAN HAZ CHEEZBURGER<br />
<br />
KILOSECONDS GETZ ANOTHR 3600 OF THOSE TODAYS OWN tm_hour<br />
KILOSECONDS GETZ ANOTHR 60 OF THOSE TODAYS OWN tm_min<br />
KILOSECONDS GETZ ANOTHR PILE OF THOSE TODAYS OWN tm_sec<br />
<br />
VISIBLE "OMG IT'S" AND KILOSECONDS SMASHES INTO 1000.0 AND "KILOSECONDS"<br />
<br />
== Lua ==<br />
This version displays the time once<br />
io.write("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds\n")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks/1000 . " kiloseconds\n");<br />
?><br />
<br />
== PLT Scheme == <br />
(let* ([date-struct (seconds->date (current-seconds))]<br />
[seconds (date-second date-struct)]<br />
[minutes (date-minute date-struct)]<br />
[hours (date-hour date-struct)])<br />
(display (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Scala ==<br />
Could be done shorter, but this demonstrates some nice Scala features.<br />
import java.util.Calendar<br />
<br />
object Kilosecond {<br />
private implicit def enrichCalendar(c: Calendar) = new CalendarWrapper(c)<br />
<br />
def main(args: Array[String]) = {<br />
val c = Calendar.getInstance<br />
<br />
println("Kiloseconds: " + c.kiloseconds)<br />
}<br />
<br />
private class CalendarWrapper(c: Calendar) {<br />
def kiloseconds = {<br />
val hours = c.get(Calendar.HOUR_OF_DAY)<br />
val minutes = c.get(Calendar.MINUTE)<br />
val seconds = c.get(Calendar.SECOND)<br />
<br />
(hours * 3600 + minutes * 60 + seconds) / 1000.0<br />
}<br />
}<br />
}<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'<br />
<br />
== Weechat Plugin ==<br />
Requires weechat version 0.3.0+<br />
[http://weechat.flashtux.org/dev/scripts/kiloseconds.py kiloseconds.py]<br />
<br />
== IRSSI Plugin ==<br />
#!/usr/bin/perl<br />
<br />
use vars qw($VERSION %IRSSI);<br />
use Irssi;<br />
use strict;<br />
$VERSION = '0.10';<br />
%IRSSI = (<br />
authors => 'Ben Duffield',<br />
contact => 'jebavarde AT gmail DOT com',<br />
name => 'kiloseconds',<br />
description => 'Reports the time in kiloseconds',<br />
license => 'GPL',<br />
url => 'http://wiki.archlinux.org/index.php/Kiloseconds',<br />
changed => 'no idea',<br />
); <br />
<br />
<br />
sub cmd_kiloseconds {<br />
my ($data, $server, $witem) = @_;<br />
my $output;<br />
my $ks;<br />
my $s;<br />
my $m; <br />
my $h;<br />
<br />
($s,$m,$h) = localtime();<br />
$ks = ($h*3600+$m*60+$s)/1000; <br />
<br />
$output = sprintf("Current time: %.3f kiloseconds", $ks);<br />
<br />
<br />
if ($output) {<br />
if ($witem && ($witem->{type} eq "CHANNEL" || $witem->{type} eq "QUERY")) {<br />
$witem->command("MSG ".$witem->{name}." $output");<br />
}<br />
else {<br />
Irssi::print("This is not a channel/query window :b");<br />
}<br />
}<br />
}<br />
<br />
Irssi::command_bind('kiloseconds', 'cmd_kiloseconds');</div>Bavardagehttps://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=70749User:Haxit/Kiloseconds2009-06-17T18:28:07Z<p>Bavardage: /* PHP */</p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
(Hour * 3600 + Minutes * 60 + Seconds)/1000.<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== LOLCODE (LOLPython) ==<br />
[http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html LOLPython here]<br />
<br />
IN MAI time GIMME localtime LIKE NOW<br />
TODAYS CAN HAZ NOW THING<br />
<br />
KILOSECONDS CAN HAZ EASTERBUNNY<br />
PILE CAN HAZ CHEEZBURGER<br />
<br />
KILOSECONDS GETZ ANOTHR 3600 OF THOSE TODAYS OWN tm_hour<br />
KILOSECONDS GETZ ANOTHR 60 OF THOSE TODAYS OWN tm_min<br />
KILOSECONDS GETZ ANOTHR PILE OF THOSE TODAYS OWN tm_sec<br />
<br />
VISIBLE "OMG IT'S" AND KILOSECONDS SMASHES INTO 1000.0 AND "KILOSECONDS"<br />
<br />
== Lua ==<br />
This version displays the time once<br />
io.write("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds\n")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks/1000 . " kiloseconds\n");<br />
?><br />
<br />
== PLT Scheme == <br />
(let* ((date-struct (seconds->date (current-seconds)))<br />
(seconds (date-second date-struct))<br />
(minutes (date-minute date-struct))<br />
(hours (date-hour date-struct)))<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'</div>Bavardagehttps://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=70748User:Haxit/Kiloseconds2009-06-17T18:27:34Z<p>Bavardage: /* LOLCODE (LOLPython) */</p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
(Hour * 3600 + Minutes * 60 + Seconds)/1000.<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== LOLCODE (LOLPython) ==<br />
[http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html LOLPython here]<br />
<br />
IN MAI time GIMME localtime LIKE NOW<br />
TODAYS CAN HAZ NOW THING<br />
<br />
KILOSECONDS CAN HAZ EASTERBUNNY<br />
PILE CAN HAZ CHEEZBURGER<br />
<br />
KILOSECONDS GETZ ANOTHR 3600 OF THOSE TODAYS OWN tm_hour<br />
KILOSECONDS GETZ ANOTHR 60 OF THOSE TODAYS OWN tm_min<br />
KILOSECONDS GETZ ANOTHR PILE OF THOSE TODAYS OWN tm_sec<br />
<br />
VISIBLE "OMG IT'S" AND KILOSECONDS SMASHES INTO 1000.0 AND "KILOSECONDS"<br />
<br />
== Lua ==<br />
This version displays the time once<br />
io.write("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds\n")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks . " kiloseconds\n");<br />
?><br />
<br />
== PLT Scheme == <br />
(let* ((date-struct (seconds->date (current-seconds)))<br />
(seconds (date-second date-struct))<br />
(minutes (date-minute date-struct))<br />
(hours (date-hour date-struct)))<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'</div>Bavardagehttps://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=70745User:Haxit/Kiloseconds2009-06-17T18:19:26Z<p>Bavardage: lolcode</p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
(Hour * 3600 + Minutes * 60 + Seconds)/1000.<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== LOLCODE (LOLPython) ==<br />
[http://www.dalkescientific.com/writings/diary/archive/2007/06/01/lolpython.html LOLPython here]<br />
<br />
IN MAI time GIMME localtime LIKE NOW<br />
TODAYS CAN HAZ NOW THING<br />
<br />
KILOSECONDS CAN HAZ EASTERBUNNY<br />
PILE CAN HAZ CHEEZBURGER<br />
<br />
KILOSECONDS GETZ ANOTHR 3600 OF THOSE TODAYS OWN tm_hour<br />
KILOSECONDS GETZ ANOTHR 60 OF THOSE TODAYS OWN tm_min<br />
KILOSECONDS GETZ ANOTHR PILE OF THOSE TODAYS OWN tm_sec<br />
<br />
VISIBLE "OMG IT'S" AND KILOSECONDS AND "KILOSECONDS"<br />
<br />
== Lua ==<br />
This version displays the time once<br />
io.write("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds\n")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks . " kiloseconds\n");<br />
?><br />
<br />
== PLT Scheme == <br />
(let* ((date-struct (seconds->date (current-seconds)))<br />
(seconds (date-second date-struct))<br />
(minutes (date-minute date-struct))<br />
(hours (date-hour date-struct)))<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'</div>Bavardagehttps://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=70738User:Haxit/Kiloseconds2009-06-17T16:49:16Z<p>Bavardage: /* PHP */</p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
(Hour * 3600 + Minutes * 60 + Seconds)/1000.<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Lua ==<br />
This version displays the time once<br />
io.write("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds\n")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks . " kiloseconds\n");<br />
?><br />
<br />
== PLT Scheme == <br />
(let* ((date-struct (seconds->date (current-seconds)))<br />
(seconds (date-second date-struct))<br />
(minutes (date-minute date-struct))<br />
(hours (date-hour date-struct)))<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'</div>Bavardagehttps://wiki.archlinux.org/index.php?title=User:Haxit/Kiloseconds&diff=70737User:Haxit/Kiloseconds2009-06-17T16:48:59Z<p>Bavardage: </p>
<hr />
<div>The '''kiloseconds''' project is a very sophisticated and exquisite, ego-boosting and mind-blowing (albeit perhaps a bit over-engineered) project which aims to provide its audience with the time in kiloseconds, since we cannot live without it.<br />
<br />
== Bash ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(date +%x)))/1000)) kiloseconds."<br />
<br />
== Bash (fixed invalid date bug ;) ==<br />
echo "It's $((($(date +%s) - $(date +%s -d $(LC_ALL="C" date +%x)))/1000)) kiloseconds."<br />
<br />
== C ==<br />
#include <stdio.h><br />
#include <time.h><br />
<br />
int main()<br />
{<br />
struct tm *t;<br />
time_t now;<br />
float ks;<br />
time(&now);<br />
t=localtime(&now);<br />
ks=(t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
printf("it is %.2f kiloseconds\n",ks/1000);<br />
return 0;<br />
}<br />
<br />
== C++ ==<br />
#include <iostream><br />
using namespace std;<br />
<br />
int main()<br />
{<br />
time_t now;<br />
time(&now);<br />
struct tm *t = localtime(&now);<br />
float ks = (t->tm_hour*3600 + t->tm_min*60 + t->tm_sec);<br />
cout << "it is " << ks/1000 << " kiloseconds" << endl;<br />
return 0;<br />
}<br />
<br />
== Clojure ==<br />
(import '(java.util Calendar))<br />
<br />
(defn kiloseconds<br />
"Current time in kiloseconds."<br />
[]<br />
(let [calendar (Calendar/getInstance)<br />
hours (. calendar (get Calendar/HOUR_OF_DAY))<br />
minutes (. calendar (get Calendar/MINUTE))<br />
seconds (. calendar (get Calendar/SECOND))<br />
kiloseconds (/ (+ (* hours 3600) (* minutes 60) seconds) 1000)]<br />
(println (str "Kiloseconds: " (float kiloseconds)))))<br />
<br />
;; call it <br />
(kiloseconds)<br />
<br />
== Eiffel ==<br />
class<br />
APPLICATION<br />
<br />
inherit<br />
ARGUMENTS<br />
<br />
create<br />
make<br />
<br />
feature {NONE} -- Initialization<br />
<br />
make<br />
-- Run application.<br />
local<br />
time: TIME<br />
kilo_seconds: INTEGER<br />
do<br />
create time.make_now<br />
kilo_seconds := ((time.hour * 3600 + time.minute * 60 + time.second) / 1000).floor<br />
io.put_integer (kilo_seconds)<br />
io.new_line<br />
end<br />
<br />
end<br />
<br />
== Erlang ==<br />
-module(kiloseconds).<br />
-export([kilotime/0]).<br />
kilotime() -><br />
{Hour,Minutes,Seconds} = erlang:time(),<br />
(Hour * 3600 + Minutes * 60 + Seconds)/1000.<br />
<br />
== Haskell ==<br />
import Data.Time<br />
<br />
diffTimeToKiloSeconds diffTime = (fromRational $ toRational diffTime) / 1000<br />
secondsSinceMidnight = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
kiloSecondsSinceMidnight = diffTimeToKiloSeconds . secondsSinceMidnight<br />
<br />
main = do localTime <- getZonedTime<br />
putStrLn $ "It's "<br />
++ show (kiloSecondsSinceMidnight localTime)<br />
++ " kiloseconds"<br />
<br />
A version with fixed-width decimal output:<br />
<br />
import Data.Time<br />
<br />
getS = timeOfDayToTime . localTimeOfDay . zonedTimeToLocalTime<br />
getKS s = (fromRational $ toRational s) / 1000<br />
formatKS n ks = let (b,a) = properFraction ks<br />
c = round $ a * 10^n<br />
in show(b) ++ "." ++ show(c)<br />
ks = formatKS 2 . getKS . getS<br />
<br />
main = do<br />
c <- getZonedTime<br />
putStrLn ("Current time: " ++ (ks c) ++ " kiloseconds")<br />
<br />
== Java ==<br />
import java.util.GregorianCalendar;<br />
<br />
public class Kiloseconds {<br />
<br />
public static void main(String[] args) {<br />
<br />
GregorianCalendar calendar = new GregorianCalendar();<br />
int hours, minutes, seconds, kiloseconds;<br />
<br />
hours = calendar.get(GregorianCalendar.HOUR_OF_DAY);<br />
minutes = calendar.get(GregorianCalendar.MINUTE);<br />
seconds = calendar.get(GregorianCalendar.SECOND);<br />
kiloseconds = (hours*3600 + minutes*60 + seconds) / 1000;<br />
System.out.println(kiloseconds + "\n");<br />
<br />
}<br />
<br />
}<br />
<br />
== Javascript ==<br />
ourDate = new Date();<br />
metricTime = (ourDate.getHours() * 3600 + ourDate.getMinutes() * 60 + ourDate.getSeconds());<br />
document.write("It is: " + metricTime / 1000 + " kiloseconds.");<br />
<br />
== Lisp ==<br />
(multiple-value-bind (seconds minutes hours)<br />
(get-decoded-time)<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Lua ==<br />
This version displays the time once<br />
io.write("It is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds\n")<br />
Time is updated once per second<br />
while true do<br />
io.write("\rIt is ", (os.date("%H")*3600 + os.date("%M")*60 + os.date("%S"))/1000, " kiloseconds")<br />
io.stdout:flush()<br />
os.execute("sleep 0.7")<br />
end<br />
<br />
== Perl ==<br />
#!/usr/bin/perl<br />
($s,$m,$h) = localtime();<br />
printf "Current time: %.3f kiloseconds", ($h*3600+$m*60+$s)/1000;<br />
<br />
== PHP ==<br />
<?php<br />
$t = localtime(time(), true);<br />
$ks = $t['tm_hour']*3600 + $t['tm_min']*60 + $t['tm_sec'];<br />
fwrite(STDOUT, "It's " . $ks . " kiloseconds\n");<br />
?><br />
<br />
<br />
== PLT Scheme == <br />
(let* ((date-struct (seconds->date (current-seconds)))<br />
(seconds (date-second date-struct))<br />
(minutes (date-minute date-struct))<br />
(hours (date-hour date-struct)))<br />
(print (/ (+ seconds<br />
(* minutes 60)<br />
(* hours 3600))<br />
1000.0)))<br />
<br />
== Python ==<br />
import time<br />
tm = time.localtime()<br />
print (tm.tm_hour*3600+tm.tm_min*60+tm.tm_sec)/1000.0, "kiloseconds"<br />
<br />
== Ruby ==<br />
puts((Time.now.sec + Time.now.min*60 + Time.now.hour*3600) / 1000.0)<br />
<br />
== Smalltalk ==<br />
'It is ', (Time now asSeconds/1000.000) printString, ' kiloseconds'</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Kernel_Patches_and_Patchsets&diff=42490Kernel Patches and Patchsets2008-06-02T18:38:52Z<p>Bavardage: /* NOTE on compile times - please add to this! */</p>
<hr />
<div>[[Category:Kernel (English)]]<br />
[[Category:Development (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
=== Using popular patches and patchsets - contributions '''greatly''' appreciated!===<br />
<br />
The number of posts on the forums about kernel patches and patchsets has been steadily increasing, prompting the drafting of this document which aims to be a definitive guide. It seems it would also be useful to reduce the need for every wiki to include a kernel patch howto!<br />
<br />
There are lots of reasons to patch your kernel, the major ones are for performance or support for non-mainline features such as reiser4 file system support. Other reasons might include fun and to see how it is done and what the improvements are.<br />
<br />
However, it is important to note that the best way to increase the speed of your system is to first tailor your kernel to your system, especially the architecture and processor type. For this reason using pre-packaged versions of custom kernels with generic architecture settings is not recommended or really worth it. A further benefit is that you can reduce the size of your kernel (and therefore build time) by not including support for things you don't have or use. For example, I always start with the stock kernel config when a new kernel version is released and I remove support for things like bluetooth, video4linux, 1000Mbit ethernet, etc. Stuff '''I''' know I won't use '''before''' i build my next kernel! However, this page is not about customizing your kernel config but I would recommend that as a first step to be combined with a patchset later.<br />
<br />
'''PLEASE NOTE - most patchsets have a disclaimer attached to them - this is for good reason!'''<br />
<br />
This document attempts to cover:<br />
* How to install the patched kernels<br />
* What the patchsets do and where to get them<br />
<br />
==== How to install them====<br />
<br />
This is very easy ''if'' you have used abs and <code>makepkg</code> before, and easiest with the latest kernels. If you haven't built any custom packages yet you may like to leave this till after you have some experience. See also: [[ABS - The Arch Build System]] and [[The Arch package making HOW-TO - with guidelines]]<br />
<br />
If you haven't actually patched or customized a kernel before it is not that hard and there are many PKGBUILDS on the forum for individual patchsets. However, I would advise you to start from scratch with a bit of research on the benefits of each patchset rather than jumping on the nearest bandwagon! This way you'll learn much more about what you are doing rather than just choosing a kernel at startup and wondering what it actually does.<br />
<br />
The following wiki pages have also been written to aid the process of building a kernel with ABS:<br />
<br />
* [[Custom Kernel Compilation with ABS]] - this has been written especially to account for the variables used when patching the latest kernel versions, using the standard kernel versioning variables - a special patch version is also available<br />
<br />
See also:<br />
* [[Kernel Compilation]]<br />
<br />
==== NOTE on compile times - please add to this!====<br />
<br />
You might be wondering how long it takes to build a kernel. As I already said that depends on the size (i.e. what drivers are included) but also on your hardware (CPU, RAM) and (ironically) which kernel you are already running!<br />
<br />
;DibbleTheWrecker<br />
:approx 1h - P3M 1Ghz<br />
;Mith<br />
:approx 20min - AMD AthlonXP2200+<br />
;RedShift<br />
:approx <10 min - AMD Athlon64 3500+/ 1 GB RAM<br />
:approx 50 min - Pentium III 1 Ghz / 512 MB RAM<br />
:approx 30 min - Dual Pentium III 866 Mhz / 1 GB RAM<br />
;Me (iphitus?)<br />
:approx 15 min - AMD AthlonXP2000+ / 512 MB RAM<br />
;hellwoofa<br />
:approx 15 min (1st run) / 6 min (2nd) - AMD AthlonXP3000+ / 512 MB RAM and [[Faster compiling and makepkg with ccache HOWTO|ccache]]<br />
;Bavardage<br />
:approx 30 min - Intel CoreDuo T2050 @ 1.60GHz (with -j 4 makeflags)<br />
<br />
=== Major patchsets===<br />
<br />
First of all it is important to note that patchsets are developed by a variety of people. Some of these people are actually involved in the production of the linux kernel and others are hobbyists - this ''should'' be considered to reflect a level of reliability and stability!<br />
<br />
It is also worth noting that some patchsets are built on the back of other patchsets (which may or may not be reflected in the title of the patch). Patchsets (and kernel updates) can be released '''very''' frequently and often it is not worth keeping up with ALL of them so don't go crazy, unless you make it your hobby!<br />
<br />
You can search google for more sets - remember to use quotes <code>"-nitro"</code> for example otherwise google will deliberately '''NOT''' show the results you want!<br />
<br />
Could people please add their experiences and comments about different patchsets below esp. re: stability (crashes), reliability (fixes) and performance.<br />
<br />
NOTE - this section is for '''information only''' - clearly no guarantees of stability or reliability are implied by inclusion on this page.<br />
<br />
==== -beyond====<br />
'''Note''': The beyond patchset development has been discontinued and is therefore not available in any Arch repositories.<br />
<br />
Beyond is a patchset based on the CK patchset. Beyond aims to include a variety of popular features and updates that have not yet made it to the vanilla kernel, while remaining relatively stable. Con Kolivas' CK patchset is the most important part of Beyond, as it provides the great interactivity and responsiveness improvements. <br />
<br />
website: http://iphitus.loudas.com/beyond.html<br />
<br />
==== -ck ====<br />
<br />
'''Note''': The -ck patchset has been discontinued as of Linux 2.6.22-ck1. A replacement is the -rt patchset (see below).<br />
<br />
These are patches designed to improve system responsiveness with specific emphasis on the desktop, but suitable to any workload. The patches are created and maintained by Con Kolivas, his site is at http://members.optusnet.com.au/ckolivas/kernel/. Con maintains a full set but also provides the patches broken down so you can add only those you prefer.<br />
<br />
The -ck patches can be found at http://ck.kolivas.org/patches/2.6/<br />
<br />
==== -rt ====<br />
<br />
This patchset is maintained by a small group of core developers, led by Ingo Molnar. This patch allows nearly all of the kernel to be preempted, with the exception of a few very small regions of code ("raw_spinlock critical regions"). This is done by replacing most kernel spinlocks with mutexes that support priority inheritance, as well as moving all interrupt and software interrupts to kernel threads. <br />
<br />
It further incorporates high resolution timers - a patch set, which is independently maintained.<br />
<br />
[as said from the [http://rt.wiki.kernel.org/index.php/CONFIG_PREEMPT_RT_Patch Real-Time Linux Wiki]]<br />
<br />
patch at http://www.kernel.org/pub/linux/kernel/projects/rt/<br />
<br />
==== -grsecurity====<br />
<br />
Grsecurity is a security focused patchset. It adds numerous security related features such as Role-Based Access Control and utilizes features of the PaX project. It can be used on a desktop but a public server would receive the greatest benefit. Some applications are incompatible with the additional security measures implemented by this patchset. If this occurs, consider using a lower security level.<br />
<br />
The -grsecurity patches can be found at http://grsecurity.net<br />
<br />
==== -mm====<br />
<br />
A patchset so popular that it even has prebuilt Arch packages in the unstable repository, but that shouldn't stop you from playing with it yourself! This patchset is maintained by [http://www.zip.com.au/~akpm/ Andrew Morton] and aims to increase the stability and performance of the Linux kernel. He aims to introduce bug fixes more quickly than mainline kernel and offers increased speed through a new disk I/O scheduler and realtime computing modifications, plus more.<br />
<br />
The -mm patches can be found at ftp://ftp.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/<br />
<br />
==== -nitro====<br />
<br />
Another very popular patchset and one of the most discussed on the Arch forums, but it is not the most reliable or stable. Very popular with some gentoo users but disregarded as amateur by others. This patchset is predominately built on other patchsets. -nitro is maintained by a gentoo user and most frequently discussed on the gentoo forums http://forums.gentoo.org/.<br />
<br />
==== - Tiny-Patches====<br />
"The -tiny tree is a series of patches against the 2.6 mainline Linux kernel to reduce its memory and disk footprint, as well as to add features to aid working on small systems. Target users are developers of embedded system and users of small or legacy machines such as 386s"<br />
<br />
and maybe also for ricers ;-)<br />
<br />
http://www.selenic.com/<br />
<br />
==== -fallen====<br />
A newer patchset, aimed at providing most of the patches that -beyond had. It has the -ck patchset, fbsplash, reiser4, suspend2, latest 2.6.x.y patch, ACPI DSDT, squashfs, and Genpatches.<br />
<br />
http://www.fallendusk.org/linux_patches/fallen/<br />
<br />
==== -viper====<br />
"The main goal of this patchset is pretty much to offer the latest features, decrease latencies, decrease overhead, and improve interactivity. The only difference is experimental versions of everything."<br />
<br />
Note that the creator and maintainer of this patchset passed away July 2007: http://forums.gentoo.org/viewtopic-t-572071.html<br />
<br />
=== Individual patches===<br />
<br />
These are patches which can be simply included in any build of a vanilla kernel or incorporated (probably with some major tweaking) into another patchset. I have included some common ones for starters.<br />
<br />
==== Reiser4====<br />
<br />
[[Reiser4FShowto]] - http://www.namesys.com<br />
<br />
==== Gensplash/fbsplash====<br />
[[Gensplash]] - http://dev.gentoo.org/~spock/projects/<br />
<br />
----<br />
WikiMigration--[[User:Dlanor|dlanor]] 15:00, 23 Jul 2005 (EDT)</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Pacman&diff=39727Pacman2008-04-10T13:36:17Z<p>Bavardage: Added -Qu</p>
<hr />
<div>[[Category:Package management (English)]]<br />
[[Category:Utilities (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
{{i18n_links_start}}<br />
{{i18n_entry|Česky|:Pacman (Česky)}}<br />
{{i18n_entry|Dansk|:Pacman_(Dansk)}}<br />
{{i18n_entry|Deutsch|:Pacman (Deutsch)}}<br />
{{i18n_entry|English|:Pacman}}<br />
{{i18n_entry|Español|:Pacman (Español)}}<br />
{{i18n_entry|Français|:Pacman (Français)}}<br />
{{i18n_entry|Italiano|:Pacman (Italiano)}}<br />
{{i18n_entry|Nederlands|:Pacman (Nederlands)}}<br />
{{i18n_entry|Polski|:Pacman (Polski)}}<br />
{{i18n_entry|Português de Portugal|:Pacman (Portugues)}}<br />
{{i18n_entry|Romanian|:Pacman (română)}}<br />
{{i18n_entry|Русский|:Pacman (Русский)}}<br />
{{i18n_entry|简体中文|:Pacman (简体中文)}}<br />
{{i18n_entry|한국어|:Pacman (한국어)}}<br />
{{i18n_links_end}}<br />
<br />
==Overview==<br />
The '''[http://archlinux.org/pacman/ Pacman]''' package manager is one of the great highlights of Arch Linux. It combines a simple binary package format with an easy-to-use build system (see [[makepkg]] and [[ABS]]). '''Pacman''' makes it possible to easily manage packages, whether they be from the official Arch repositories or the user's own builds.<br />
<br />
'''Pacman''' keeps the system up to date by synchronizing package lists with the master server. This server/client model also allows you to download/install packages with a simple command, complete with all required dependencies.<br />
<br />
'''Pacman''' is written in the C programming language, so it is fast, light and very agile. It uses the .tar.gz package format, which further enhances its speed; Gzipped tarballs, though slightly larger, are decompressed much faster than their Bzipped counterparts, and are therefore generally installed more expediently. <br />
<br />
==Usage==<br />
<br />
To really learn what pacman can do, read [http://archlinux.org/pacman/pacman.8.html man pacman]. The below is just a small sample of operations that can be performed.<br />
<br />
===Installing and Removing Packages===<br />
Before installing and upgrading packages, it is a good idea to synchronize the local package database with the remote repositories.<br />
<br />
pacman -Sy<br />
or<br />
pacman --sync --refresh<br />
<br />
To install or upgrade a single package or list of packages (including dependencies), issue the following command:<br />
<br />
pacman -S package_name1 package_name2<br />
<br />
Sometimes there are more versions of a package in different repositories (e.g. extra and testing). You can specify which one to install:<br />
<br />
pacman -S extra/package_name<br />
pacman -S testing/package_name<br />
<br />
You can also refresh the package database before installing a package in one command:<br />
<br />
pacman -Sy package_name<br />
<br />
To remove a single package, leaving all of its dependencies installed:<br />
<br />
pacman -R package_name<br />
<br />
To remove all of the packages dependencies which aren't used by any other installed package:<br />
<br />
pacman -Rs package_name<br />
<br />
To remove a package without checking dependencies:<br />
<br />
pacman -Rd package_name<br />
<br />
===Upgrading the System===<br />
<br />
'''Pacman''' can update all packages on the system with just one command. This could take quite a while depending on how up-to-date your system is.<br />
<br />
pacman -Su<br />
<br />
However, the best option is to synchronize the repository databases AND update your system in one go with the following:<br />
<br />
pacman -Syu<br />
<br />
===Querying the Package Database===<br />
<br />
'''Pacman''' can search the package database for a list of packages, you can enter part of the package name to search for all packages matching the string:<br />
<br />
pacman -Ss package<br />
<br />
To search installed packages only:<br />
<br />
pacman -Qs package<br />
<br />
Once you know the name of the package you are looking for, you can display some information on the package. Note that ''query info'' (-Qi) will show more info than ''sync info'' (-Si), as long as the package is installed.<br />
<br />
pacman -Si package <br />
pacman -Qi package<br />
<br />
For a list of files contained in a package:<br />
<br />
pacman -Ql package<br />
<br />
For a list of files formerly installed as dependencies, but no longer in use by any currently installed packages (orphans):<br />
<br />
pacman -Qdt<br />
<br />
For a list of files explicitly installed, but not required by any other package:<br />
<br />
pacman -Qet<br />
<br />
You can also query what package a file on your system belongs to.<br />
<br />
pacman -Qo /path/to/file<br />
<br />
For a list of packages which can be updated:<br />
pacman -Qu<br />
<br />
===Other Usage===<br />
<br />
'''Pacman''' is quite an extensive package management tool, here is just a brief collection of other features.<br />
<br />
* Download a package without installing it:<br />
pacman -Sw package_name<br />
<br />
* Install a local package (not from a repository):<br />
pacman -U /path/to/package/package_name-version.pkg.tar.gz<br />
You may also enter a URL:<br />
pacman -U http://www.examplepackage/repo/examplepkg.tar.gz<br />
* Fully clean the package cache (/var/cache/pacman/pkg):<br />
pacman -Scc<br />
<br />
* Reinstall a package (that can't be removed first because of dependencies problems):<br />
pacman -Sf package_name<br />
<br />
For a more detailed list of switches please refer to <code>pacman --help</code> or <code>man pacman</code>.<br />
<br />
==Configuration==<br />
Pacman configuration is located in <code>/etc/pacman.conf</code>. In depth information about the configuration file can be found in <code>man pacman.conf</code>.<br />
<br />
===General options===<br />
General options are in [options] section. Read the man page or look in the default pacman.conf for information on what can be done here.<br />
<br />
===Repositories===<br />
In this section you define which repositories to use, as referred to in /etc/pacman.conf, and then listed in /etc/pacman.d/. They can be defined directly there or you can include them from another file. <strike>The files found in this directory include, community, core, extra, release, testing and unstable. It is important to edit each one to include the repositories you require.</strike>'''(deprecated in pacman 3.1, check edit)''' The following is an example for the official repositories which have a lot of [[mirrors]]. Avoid using ftp.archlinux.org as it is [http://www.archlinux.org/news/302/ throttled].<br />
<br />
<pre><br />
[repository-name]<br />
Server = ftp://server.net/repo<br />
</pre><br />
<br />
<pre><br />
[core]<br />
# Add your preferred servers here, they will be used first<br />
Include = /etc/pacman.d/core<br />
</pre><br />
<br><br />
'''edit:''' starting with pacman 3.1, all repositories will use the same /etc/pacman.d/mirrorlist which contains a variable '$repo'. This just cleans up the mirrorlist and removes some of the 'bloat'. No need to maintain more then mirrorlist. K.I.S.S. method.<br />
<pre><br />
[core]<br />
# Add your preferred servers here, they will be used first<br />
Include = /etc/pacman.d/mirrorlist<br />
<br />
[extra]<br />
# Add your preferred servers here, they will be used first<br />
Include = /etc/pacman.d/mirrorlist<br />
<br />
[community]<br />
# Add your preferred servers here, they will be used first<br />
Include = /etc/pacman.d/mirrorlist<br />
</pre><br />
<br />
'''n.b.''' Care should be taken when using '''testing''' repository<br />
<br />
===Errors===<br />
<br />
If you receive the following error<br />
'''not found in sync db'''<br />
this likely due to the package not being located because the repository has not been set correctly.<br />
<br />
==Related links==<br />
<br />
'''man-pages''':<br />
*[http://www.archlinux.org/pacman/pacman.8.html man pacman]<br />
*[http://www.archlinux.org/pacman/PKGBUILD.5.html man PKGBUILD]<br />
*[http://www.archlinux.org/pacman/libalpm.3.html man libalpm]<br />
*[http://www.archlinux.org/pacman/pacman.conf.5.html man pacman.conf]<br />
*[http://www.archlinux.org/pacman/makepkg.8.html man makepkg]<br />
*[http://www.archlinux.org/pacman/makepkg.conf.5.html man makepkg.conf]<br />
*[http://www.archlinux.org/pacman/repo-add.8.html man repo-add]<br />
<br />
'''other wiki-entries''':<br />
<br />
[[Improve Pacman Performance]]<br><br />
[[Colored Pacman output]]<br><br />
[[Downgrade packages]]<br><br />
[http://www.archlinux.org/pacman/pacman.conf.5.html Editing pacman.conf]<br><br />
[[Redownloading all installed packages]]<br><br />
[[Server_configuration|Server configuration in pacman.conf]]<br><br />
[[ArchLinux User-community Repository (AUR)]]<br><br />
[[Local repository HOW-TO]]<br><br />
[[Custom local repository with ABS and gensync]]<br><br />
[[Howto Upgrade via Home Network]] (Network Shared Pacman Cache)<br><br />
[[rucksack]]<br><br />
[[Pacman GUI Frontends]]<br><br />
[[Pacman_Aliases|Pacman Aliases (for bash)]]<br />
[[Mirrors]]<br />
<br />
== External Links ==<br />
[http://archux.com/page/using-pacman Using Pacman]</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Hdup&diff=38965Hdup2008-03-21T17:25:44Z<p>Bavardage: /* Installing/running/restoring */ - fixed typo and grammar</p>
<hr />
<div>[[Category:Development (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
== Intro ==<br />
<br />
This wiki page contains a guide on how to set up [http://www.miek.nl/projects/hdup2/hdup.html hdup], "The little, spiffy, backup tool". (Don't be discouraged by the fact that on its website it says "Unmaintained!". It's mature program, and that warning means only that its author, Miek Gieben, develops and uses a similar program (rdup), which is a bit more difficult to use.) Although it's a command line program, it's easy to set up, so don't be afraid.<br />
<br />
=== Features ===<br />
* archives are tar.bz2 (or tar.gz)<br />
* incremental backups (monthly-weekly-daily scheme)<br />
* backups over ssh<br />
* encrypted backups (mcrypt, gpg)<br />
<br />
=== Other backup programs ===<br />
Let's list some other programs dedicated to making backups, grouped by "type":<br />
<br />
* rsync type: Those which maintain a copy of the directory you want to keep a backup of, together with files which describe how did the contents change from the last backup (the so-called 'diffs'). Hence, they are inherently incremental, but usually they don't have compression/encryption. On the other hand, a working copy of everything is immediately available, no decompression/decryption needed. Finally the way it works makes it hard to burn backups to cd/dvd.:<br />
** command line: [http://www.samba.org/rsync/ rsync], [http://www.nongnu.org/rdiff-backup/ rdiff-backup], [http://www.rsnapshot.org rsnapshot]<br />
** gui: [http://www.flyback-project.org/ flyback], [http://areca.sourceforge.net/ areca], [https://wiki.ubuntu.com/TimeVault timevault]<br />
* "just copy everything into one big archive, but support writing to cd/dvd"-type: [http://www2.backup-manager.org/ backup-manager]<br />
* a one which has support for incremental backups, tarring and encrypting is [http://www.nongnu.org/duplicity/ duplicity]. Functioning is very similar to hdup, but: <br />
** the files backed up are "randomly" distributed between encrypted tar archives, which makes it harder to recover a particular file (hdup uses just one file: this is a drawback if you backup a lot of data at once)<br />
** you can backup just one directory at a time (while with hdup you can specify as many as you want in one backup profile)<br />
<br />
You should think about your needs, read a bit about various possibilities. For instance, a popular solution for managing your configuration files is to use a versioning system (like [http://www.selenic.com/mercurial/wiki/ mercurial] or [http://git.or.cz/ git])<br />
<br />
== Installing/running/restoring ==<br />
<br />
=== Installing and setting hdup up ===<br />
<br />
* hdup is in [extra] repo, so you can install it via pacman:<br />
pacman -S hdup<br />
* We need to edit the configuration file '''/etc/hdup/hdup.conf'''. There's one supplied, so you can just edit that one; or you can use the minimal one listed here:<br />
[global]<br />
# to which dir the archives will be written<br />
archive dir = /vol/backup<br />
# chown the archives to this user<br />
user = <yourusername><br />
<br />
[my-comp]<br />
# what to backup, separate with ,.<br />
# For directories add closing slash, like /home/<br />
dir = /home/,/var/abs/local/<br />
# don't include theses directories<br />
exclude = lost\+found/, /proc/, /dev/, /sys/<br />
* You '''need to modify''' at least the following options:<br />
** '''archive dir''': that's where the backups will be written to<br />
** '''user''': created archives will be chowned to this user; you can just use your username. This is needed since hdup needs to be run as root.<br />
** '''dir''': that's the list of directories whose contents you want to back up).<br />
<br />
The rest of the comments about the config file can be skipped on the first<br />
reading. They describe various other options you can use if the hdup.conf file:<br />
* You can have more that one ''profile'' (the one used above is named '''my-comp'''). This means that you can have a couple of independent backup schemes. For instance, you might want to have another one for your webpages:<br />
[my-webpages]<br />
dir = /var/www/<br />
* To have a simple means of excluding some directories, use the '''nobackup''' option. It specifies the filename, which if it exists in a directory, then that directory is excluded from backing up.<br />
nobackup = .nobackup<br />
This can be used for example to exclude backing up of opera cache, by creating and empty .nobackup file in the cache directory:<br />
touch ~/.opera/cache4/.nobackup<br />
* You can specify the compression algorithm used:<br />
compression = bzip<br />
compression level = 6<br />
* hdup refuses to restore backups to / by default, since it can be dangerous. To override this, use<br />
# allow restoring to /<br />
force = yes<br />
<br />
=== Running hdup ===<br />
<br />
Let's first explain the monthly-weekly-daily scheme of backups. The 'monthly'<br />
archives contain all the data you specify to backup. The 'weekly' archives<br />
contain only those files, which have changed from the last 'monthly' backup.<br />
Finally, 'daily' contain only those which have changed from the last 'weekly'<br />
backup.<br />
<br />
Of course, 'monthly', 'weekly' and 'daily' are just names, you don't need to<br />
perform backups in these intervals. But you cannot perform a 'weekly', unless<br />
you have at least one 'monthly', etc.<br />
<br />
So, how does hdup implement this scheme?<br />
<br />
As root, you can run hdup with the command like<br />
hdup monthly my-comp<br />
This creates a directory 'my-comp' in the directory you specified in the config file (/vol/backup), and inside it two other directories: 'etc' and (current date) '2008-02-23'. The 'etc' one contains some hdup's files, and the '2008-02-23' one will have a big .tar.bz2 archive in it. That's your backup.<br />
<br />
After some time after 'monthly' backup, you decide you want to backup again. Now you can run hdup as<br />
hdup weekly my-comp<br />
and hdup will archive only what has changed from the 'monthly', and the archive will be put into another dir named after current date in /vol/backup/my-comp.<br />
<br />
It should be clear now how the backing up works. Note that if hdup cannot find a 'monthly' and you ask it to do a 'weekly', it will complain. See the tips section.<br />
<br />
=== Restoring backups ===<br />
<br />
To restore, you need to have all 'parent' archives (ie. if you want to restore a weekly backup, you also need to have its 'monthly' available). The command for restoring is<br />
hdup restore my-comp 2008-01-31 /somedir<br />
With this, hdup will try to restore things as they've been up to the date specified, and it will unpack to the directory /somedir. You can force it to unpack right away to / (see 'force' option above), but be very careful with this!<br />
<br />
Note that the backups are just .tar.bz2 archives, so if you need a particular file from a particular date, just use any archive manager (or tar and bzip2) to open the archive and copy the needed file over.<br />
<br />
=== More goodies: encryption and ssh ===<br />
<br />
If you've got here, let me remind you that '''man hdup''' and '''man hdup.conf''' are your friends!<br />
<br />
* For gpg encryption, you want to add something like<br />
algorithm = gpg<br />
key = <your gpg key identifier><br />
either to [global] (then it's going to be used for all profiles), or just to a profile part. The archives will then be encrypted with your public key (so you can only decrypt them with your secret key). Note that you can decrypt them manually with<br />
gpg -d <archive file><br />
in case you need it.<br />
<br />
* For other encryption (e.g. mcrypt), just add<br />
algorithm = mcrypt<br />
In this case, hdup will ask for a password both when archiving and restoring.<br />
<br />
I haven't tried the backups over ssh... so if anybody feels like, please update this wiki.<br />
<br />
=== Tips ===<br />
<br />
* You can of course burn the archives to cd/dvd with any burning software you like. The only thing to remember here is that the 'parent' archive is needed when you're doing a 'child' backup (like you need 'monthly' for 'weekly'). However, if you're tight on space, this can be achieved by mounting the cd/dvd with 'parent' backup, and soft linking its directory into /vol/backup, so that hdup can find it there.</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Canon_iP4300&diff=37842Canon iP43002008-02-29T18:44:16Z<p>Bavardage: </p>
<hr />
<div>[[Category:Printers_(English)]]<br />
=Introduction=<br />
This is a brief summary of the ways that the Canon iP4300 printer can be made to work with arch. As the printers are very similar, these techniques would very likely work with the iP4200 also.<br />
<br />
=Requirements=<br />
The following packages will very likely be needed:<br />
*cups<br />
*ghostscript<br />
*gsfonts<br />
Install with:<br />
# pacman -S cups ghostscript gsfonts<br />
<br />
For information about setting up cups, refer to [[CUPS]], however all that is really needed for the iP4300 is to start the cups daemon with:<br />
# /etc/rc.d/cups start<br />
and to add cups to the daemons line in /etc/rc.conf<br />
<br />
=Methods of getting the printer working=<br />
There are basically three options:<br />
*[[Canon_iP4300#Proprietary_Drivers|Proprietary Drivers]]<br />
*[[Canon_iP4300#Gutenprint|Gutenprint]]<br />
*[[Canon_iP4300#Turboprint|Turboprint]]<br />
==Proprietary Drivers==<br />
===Install needed packages===<br />
You will need the package rpmextract<br />
# pacman -S rpmextract<br />
Now create a directory somewhere (for the sake of this tutorial let this directory be ~/canon) and cd to it.<br />
===Download drivers===<br />
Download cnijfilter-ip4300-2.70-1.i386.rpm and cnijfilter-common-2.70-1.i386.rpm from ftp://download.canon.jp/pub/driver/bj/linux/ and put into the folder you created, or:<br />
# wget ftp://download.canon.jp/pub/driver/bj/linux/cnijfilter-common-2.70-1.i386.rpm<br />
# wget ftp://download.canon.jp/pub/driver/bj/linux/cnijfilter-ip4300-2.70-1.i386.rpm<br />
<br />
Now extract the rpms:<br />
# rpmextract.sh cnijfilter-ip4300-2.70-1.i386.rpm <br />
# rpmextract.sh cnijfilter-common-2.70-1.i386.rpm<br />
<br />
Now for the monotonous bit (there is probably a much quicker way to do this using scripts etc, but this way is simple and allows you to see what goes where)<br />
===Move the files===<br />
The command rpmextract.sh should have created a usr/ directory in the folder with the rpms. Copy every file in this directory's subfolders into the corresponding actual location. e.g. copy the files in ~/canon//usr/lib/ to /usr/lib/<br />
Do this for all files in all subdirectories (however I as my language is english, I didn't bother copying the locale folder in ~/canon/usr/local/share and everything still seems to work fine.<br />
<br />
===Install the printer with CUPS===<br />
If cups is not already running, start it with<br />
# /etc/rc.d/cups start<br />
<br />
Now point your browser of choice at http://localhost:631<br />
This should present the cups web interface. If not, ensure that cups is started (see above) and that your hosts are set-up correctly (or see the [[CUPS]] article).<br />
*Click Add Printer<br />
*Fill in the Name, Description and Location (not really very important)<br />
*Choose the connection method for your printer, and fill in any details required for this.<br />
*Now you will be prompted for a Make/Manufacturer - choose Provide a ppd file (click browse)<br />
*Navigate to /usr/share/cups/model/ and choose canonip4300.ppd<br />
<br />
The printer should now be installed. You could test it by pressing the Print Test Page button, or continue onto the next step to add support for higher resolutions.<br />
Bulk of information from http://www.erlandertervueren.com/ubuntu/ip4300_guide<br />
The installed PPD file doesn't allow you to select the printing quality. To fix this, back up your ppd file, then open it as root.<br />
Your ppd file will be found in /etc/cups/ppd and it's name depends upon what you called your printer.<br />
The commands below assume the printer was called Canon:<br />
# su root<br />
# <text editor here> /etc/cups/ppd/Canon.ppd<br />
<br />
Insert these lines in the file after the "Resolution" section:<br />
<br />
*OpenUI *CNQuality/Quality: PickOne<br />
*DefaultCNQuality: 3<br />
*CNQuality 2/High: "2"<br />
*CNQuality 3/Normal: "3"<br />
*CNQuality 4/Standard: "4"<br />
*CNQuality 5/Economy: "5"<br />
*CloseUI: *CNQuality<br />
<br />
The following gives a greater choice of print resolution if added to the "Resolution" section, but it is currently not know if the Quality setting impinges upon this. Note that the ip4200 only offers 600dpi in black and white. (Maybe someone could verify some of this)<br />
<br />
*Resolution 1200/1200 dpi: "<</HWResolution[1200 1200]>>setpagedevice"<br />
*Resolution 2400/2400 dpi: "<</HWResolution[2400 2400]>>setpagedevice"<br />
*Resolution 4800/4800 dpi: "<</HWResolution[4800 4800]>>setpagedevice"<br />
<br />
...and that's about it!<br />
<br />
==Gutenprint==<br />
{{stub}}<br />
==Turboprint==<br />
{{stub}}<br />
==Related Links/Additional Information==<br />
http://www.erlandertervueren.com/ubuntu/ip4300_guide/ - A guide for setting up the printer on ubuntu - may help if using gnome etc.</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Canon_iP4300&diff=37817Canon iP43002008-02-28T22:14:30Z<p>Bavardage: </p>
<hr />
<div>[[Category:Printers_(English)]]<br />
=Introduction=<br />
This is a brief summary of the ways that the Canon iP4300 printer can be made to work with arch. As the printers are very similar, these techniques would very likely work with the iP4200 also.<br />
<br />
=Requirements=<br />
The following packages will very likely be needed:<br />
*cups<br />
*ghostscript<br />
*gsfonts<br />
Install with:<br />
# pacman -S cups ghostscript gsfonts<br />
<br />
For information about setting up cups, refer to [[CUPS]], however all that is really needed for the iP4300 is to start the cups daemon with:<br />
# /etc/rc.d/cups start<br />
and to add cups to the daemons line in /etc/rc.conf<br />
<br />
=Methods of getting the printer working=<br />
There are basically three options:<br />
*[[Canon_iP4300#Proprietary_Drivers|Proprietary Drivers]]<br />
*[[Canon_iP4300#Gutenprint|Gutenprint]]<br />
*[[Canon_iP4300#Turboprint|Turboprint]]<br />
==Proprietary Drivers==<br />
===Install needed packages===<br />
You will need the package rpmextract<br />
# pacman -S rpmextract<br />
Now create a directory somewhere (for the sake of this tutorial let this directory be ~/canon) and cd to it.<br />
===Download drivers===<br />
Download cnijfilter-ip4300-2.70-1.i386.rpm and cnijfilter-common-2.70-1.i386.rpm from ftp://download.canon.jp/pub/driver/bj/linux/ and put into the folder you created, or:<br />
# wget ftp://download.canon.jp/pub/driver/bj/linux/cnijfilter-common-2.70-1.i386.rpm<br />
# wget ftp://download.canon.jp/pub/driver/bj/linux/cnijfilter-ip4300-2.70-1.i386.rpm<br />
<br />
Now extract the rpms:<br />
# rpmextract.sh cnijfilter-ip4300-2.70-1.i386.rpm <br />
# rpmextract.sh cnijfilter-common-2.70-1.i386.rpm<br />
<br />
Now for the monotonous bit (there is probably a much quicker way to do this using scripts etc, but this way is simple and allows you to see what goes where)<br />
===Move the files===<br />
The command rpmextract.sh should have created a usr/ directory in the folder with the rpms. Copy every file in this directory's subfolders into the corresponding actual location. e.g. copy the files in ~/canon//usr/lib/ to /usr/lib/<br />
Do this for all files in all subdirectories (however I as my language is english, I didn't bother copying the locale folder in ~/canon/usr/local/share and everything still seems to work fine.<br />
<br />
===Install the printer with CUPS===<br />
If cups is not already running, start it with<br />
# /etc/rc.d/cups start<br />
<br />
Now point your browser of choice at http://localhost:631<br />
This should present the cups web interface. If not, ensure that cups is started (see above) and that your hosts are set-up correctly (or see the [[CUPS]] article).<br />
*Click Add Printer<br />
*Fill in the Name, Description and Location (not really very important)<br />
*Choose the connection method for your printer, and fill in any details required for this.<br />
*Now you will be prompted for a Make/Manufacturer - choose Provide a ppd file (click browse)<br />
*Navigate to /usr/share/cups/model/ and choose canonip4300.ppd<br />
<br />
There. All done<br />
<br />
{{stub}}<br />
<br />
==Gutenprint==<br />
{{stub}}<br />
==Turboprint==<br />
{{stub}}</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Canon_iP4300&diff=37816Canon iP43002008-02-28T22:12:31Z<p>Bavardage: </p>
<hr />
<div>=Introduction=<br />
This is a brief summary of the ways that the Canon iP4300 printer can be made to work with arch. As the printers are very similar, these techniques would very likely work with the iP4200 also.<br />
<br />
=Requirements=<br />
The following packages will very likely be needed:<br />
*cups<br />
*ghostscript<br />
*gsfonts<br />
Install with:<br />
# pacman -S cups ghostscript gsfonts<br />
<br />
For information about setting up cups, refer to [[CUPS]], however all that is really needed for the iP4300 is to start the cups daemon with:<br />
# /etc/rc.d/cups start<br />
and to add cups to the daemons line in /etc/rc.conf<br />
<br />
=Methods of getting the printer working=<br />
There are basically three options:<br />
*[[Canon_iP4300#Proprietary_Drivers|Proprietary Drivers]]<br />
*[[Canon_iP4300#Gutenprint|Gutenprint]]<br />
*[[Canon_iP4300#Turboprint|Turboprint]]<br />
==Proprietary Drivers==<br />
===Install needed packages===<br />
You will need the package rpmextract<br />
# pacman -S rpmextract<br />
Now create a directory somewhere (for the sake of this tutorial let this directory be ~/canon) and cd to it.<br />
===Download drivers===<br />
Download cnijfilter-ip4300-2.70-1.i386.rpm and cnijfilter-common-2.70-1.i386.rpm from ftp://download.canon.jp/pub/driver/bj/linux/ and put into the folder you created, or:<br />
# wget ftp://download.canon.jp/pub/driver/bj/linux/cnijfilter-common-2.70-1.i386.rpm<br />
# wget ftp://download.canon.jp/pub/driver/bj/linux/cnijfilter-ip4300-2.70-1.i386.rpm<br />
<br />
Now extract the rpms:<br />
# rpmextract.sh cnijfilter-ip4300-2.70-1.i386.rpm <br />
# rpmextract.sh cnijfilter-common-2.70-1.i386.rpm<br />
<br />
Now for the monotonous bit (there is probably a much quicker way to do this using scripts etc, but this way is simple and allows you to see what goes where)<br />
===Move the files===<br />
The command rpmextract.sh should have created a usr/ directory in the folder with the rpms. Copy every file in this directory's subfolders into the corresponding actual location. e.g. copy the files in ~/canon//usr/lib/ to /usr/lib/<br />
Do this for all files in all subdirectories (however I as my language is english, I didn't bother copying the locale folder in ~/canon/usr/local/share and everything still seems to work fine.<br />
<br />
===Install the printer with CUPS===<br />
If cups is not already running, start it with<br />
# /etc/rc.d/cups start<br />
<br />
Now point your browser of choice at http://localhost:631<br />
This should present the cups web interface. If not, ensure that cups is started (see above) and that your hosts are set-up correctly (or see the [[CUPS]] article).<br />
*Click Add Printer<br />
*Fill in the Name, Description and Location (not really very important)<br />
*Choose the connection method for your printer, and fill in any details required for this.<br />
*Now you will be prompted for a Make/Manufacturer - choose Provide a ppd file (click browse)<br />
*Navigate to /usr/share/cups/model/ and choose canonip4300.ppd<br />
<br />
There. All done<br />
<br />
{{stub}}<br />
<br />
==Gutenprint==<br />
{{stub}}<br />
==Turboprint==<br />
{{stub}}</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Canon_iP4300&diff=37815Canon iP43002008-02-28T22:11:46Z<p>Bavardage: /* Proprietary Drivers */</p>
<hr />
<div>=Introduction=<br />
This is a brief summary of the ways that the Canon iP4300 printer can be made to work with arch. As the printers are very similar, these techniques would very likely work with the iP4200 also.<br />
<br />
=Requirements=<br />
The following packages will very likely be needed:<br />
*cups<br />
*ghostscript<br />
*gsfonts<br />
Install with:<br />
# pacman -S cups ghostscript gsfonts<br />
<br />
For information about setting up cups, refer to [[CUPS]], however all that is really needed for the iP4300 is to start the cups daemon with:<br />
# /etc/rc.d/cups start<br />
and to add cups to the daemons line in /etc/rc.conf<br />
<br />
=Methods of getting the printer working=<br />
There are basically three options:<br />
*[[Canon_iP4300#Proprietary_Drivers|Proprietary Drivers]]<br />
*[[Canon_iP4300#Gutenprint|Gutenprint]]<br />
*[[Canon_iP4300#Turboprint|Turboprint]]<br />
==Proprietary Drivers==<br />
===Install needed packages===<br />
You will need the package rpmextract<br />
# pacman -S rpmextract<br />
Now create a directory somewhere (for the sake of this tutorial let this directory be ~/canon) and cd to it.<br />
{{stub}}<br />
===Download drivers===<br />
Download cnijfilter-ip4300-2.70-1.i386.rpm and cnijfilter-common-2.70-1.i386.rpm from ftp://download.canon.jp/pub/driver/bj/linux/ and put into the folder you created, or:<br />
# wget ftp://download.canon.jp/pub/driver/bj/linux/cnijfilter-common-2.70-1.i386.rpm<br />
# wget ftp://download.canon.jp/pub/driver/bj/linux/cnijfilter-ip4300-2.70-1.i386.rpm<br />
<br />
Now extract the rpms:<br />
# rpmextract.sh cnijfilter-ip4300-2.70-1.i386.rpm <br />
# rpmextract.sh cnijfilter-common-2.70-1.i386.rpm<br />
<br />
Now for the monotonous bit (there is probably a much quicker way to do this using scripts etc, but this way is simple and allows you to see what goes where)<br />
===Move the files===<br />
The command rpmextract.sh should have created a usr/ directory in the folder with the rpms. Copy every file in this directory's subfolders into the corresponding actual location. e.g. copy the files in ~/canon//usr/lib/ to /usr/lib/<br />
Do this for all files in all subdirectories (however I as my language is english, I didn't bother copying the locale folder in ~/canon/usr/local/share and everything still seems to work fine.<br />
<br />
===Install the printer with CUPS===<br />
If cups is not already running, start it with<br />
# /etc/rc.d/cups start<br />
<br />
Now point your browser of choice at http://localhost:631<br />
This should present the cups web interface. If not, ensure that cups is started (see above) and that your hosts are set-up correctly (or see the [[CUPS]] article).<br />
*Click Add Printer<br />
*Fill in the Name, Description and Location (not really very important)<br />
*Choose the connection method for your printer, and fill in any details required for this.<br />
*Now you will be prompted for a Make/Manufacturer - choose Provide a ppd file (click browse)<br />
*Navigate to /usr/share/cups/model/ and choose canonip4300.ppd<br />
<br />
There. All done<br />
<br />
{{stub}}<br />
<br />
==Gutenprint==<br />
{{stub}}<br />
==Turboprint==<br />
{{stub}}</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Canon_iP4300&diff=37813Canon iP43002008-02-28T21:20:50Z<p>Bavardage: New page: =Introduction= This is a brief summary of the ways that the Canon iP4300 printer can be made to work with arch. As the printers are very similar, these techniques would very likely work wi...</p>
<hr />
<div>=Introduction=<br />
This is a brief summary of the ways that the Canon iP4300 printer can be made to work with arch. As the printers are very similar, these techniques would very likely work with the iP4200 also.<br />
<br />
=Requirements=<br />
The following packages will very likely be needed:<br />
*cups<br />
*ghostscript<br />
*gsfonts<br />
Install with:<br />
# pacman -S cups ghostscript gsfonts<br />
<br />
For information about setting up cups, refer to [[CUPS]], however all that is really needed for the iP4300 is to start the cups daemon with:<br />
# /etc/rc.d/cups start<br />
and to add cups to the daemons line in /etc/rc.conf<br />
<br />
=Methods of getting the printer working=<br />
There are basically three options:<br />
*[[Canon_iP4300#Proprietary_Drivers|Proprietary Drivers]]<br />
*[[Canon_iP4300#Gutenprint|Gutenprint]]<br />
*[[Canon_iP4300#Turboprint|Turboprint]]<br />
==Proprietary Drivers==<br />
You will need the package rpmextract<br />
# pacman -S rpmextract<br />
Now create a directory somewhere and cd to it.<br />
{{stub}}<br />
==Gutenprint==<br />
{{stub}}<br />
==Turboprint==<br />
{{stub}}</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Hibernate-script&diff=37269Hibernate-script2008-02-17T22:25:51Z<p>Bavardage: /* Editing /etc/hibernate/common.conf */</p>
<hr />
<div>[[Category:Power management (English)]]<br />
[[Category:Laptops (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
This article will describe how to suspend a computer (usually a laptop) to disk. This means that all the running processes will be saved to the hard drive and power will completely shut down. This article discusses the two main methods to accomplish this task, that is userspace suspension (uswsusp) and tuxonice (formerly known as suspend2). See the [http://suspend.sourceforge.net/ ususpend website] and the [http://www.tuxonice.net/ tuxonice website] for complete documentation. There is a third method: using the kernelspace functionalities of the vanilla kernel. However, this method is the least developed, the slowest and the less reliable. On the contrary, tuxonice and ususpend are competing in features and stability. The only method to decide which method is better for you is to try both of them. From a general point of view, we can say that uswsusp does not force you to patch, configure and compile a kernel, while tuxonice does. However, tuxonice can be used without an initrd/initramfs, while using ususpend without an initrd/initramfs is discouraged; moreover, tuxonice allows you to suspend on a regular file if you have not a swap partition, while uswsusp give this possibility only if you run an experimental and unstable mm kernel.<br />
<br />
It is important to distinguish the core method of suspension to disk from the userspace application which you use to hibernate your machine to disk. A userspace application is required because the large majority of the laptops require some quirks in order to accomplish a proficient, successful hibernation cycle: unloading modules, restarting services, unmount windows partitions and usb keys, and so on.<br />
<br />
There are two widely used userspace applications for this purpose: [[pm-utils]] and hibernate-script. You can find both of them in the extra repo. However, since in this guide we need to describe two different, competing core methods, we will focus on the hibernate-script, since only this script allows the user to choose the core method he prefers. On the contrary, [[pm-utils]], at least in the version actually distributed by arch, forces you silently to use the old vanilla method. On the other side, the script, developed by the tuxonice development team, can be used nonetheless also to hibernate your machine with the ususpend method, and even to suspend the machine to ram (actually it is an excellent tool also for this task, but we are not going to discuss this aspect in this document, see [[Suspend to RAM]]).<br />
<br />
If you prefer to use pm-utils, refer to the specific [[pm-utils|wiki article]].<br />
<br />
Thus:<br />
<br />
# pacman -S hibernate-script<br />
<br />
The discussion will be articulated in four parts. First of all, we will discuss the userspace method, secondly the tuxonice one, thirdly we will see how to use the power of the hibernate-script in order to circumvent some problems which could impair your ability to accomplish successful suspend/resume cycles. These last tips can be used with both methods. On the contrary, the first two parts will include instructions to use the hibernate-script in order to accomplish the basic operations with the two methods. In the fourth and last part, we will see how to combine suspension to disk and [[Suspend to RAM]] . <br />
<br />
When there is the need to modify the configuration of the bootloader, we will be always under the assumption that you use grub, but it should not be difficult to act analogously on the configuration of lilo.<br />
<br />
=Uswsusp method=<br />
<br />
The userspace method lets you resort to some advanced suspension abilities included in vanilla kernels > 2.6.17. You need two userspace tools, called s2disk and resume, which do what their names say. They are both included in the uswsusp package (which includes also s2ram, see [[Suspend to RAM]] ). You can find uswsusp in the AUR. The package in the AUR includes also an initramfs hook which allows you to resume properly using an initramfs.<br />
<br />
==Obtaining uswsusp==<br />
The first thing to do is to download the tarball from the AUR page. Compile the source and create the package with makepkg and install it with pacman -U.<br />
<br />
<br />
==Editing /etc/suspend.conf==<br />
On the contrary, you need to edit the s2disk configuration file, called /etc/suspend.conf. It is essential that you modify the resume device parameter:<br />
<br />
resume device = /dev/sda3<br />
<br />
It needs to point to your swap partition: in this case, the third partition of a primary pata-sata drive. It is also a good thing to enable compression, because this speeds up greatly your suspension/resume routine.<br />
<br />
Note that it is important that this configuration file be edited *before* recreating the initramfs (done below). Presently, the initramfs build process reads this configuration file, and embeds the current resume parameter. If not changed from the default '<path_to_resume_device_file>', this causes problems such as seeing, on bootup:<br />
<br />
# Could not stat the resume device file '<path_to_resume_device_file>'<br />
# Please type in the full path name to try again or press ENTER to boot the system.<br />
<br />
If you have experiencing this problem, simply edit the file as appropriate, and then rebuild the initramfs.<br />
<br />
==Recreate the intramfs==<br />
Now you need to recreate an initramfs with the new hook. So edit the /etc/mkinitcpio.conf file. In the HOOKS list add the uresume hook (it is different from the resume hook, which is on the contrary required by the tuxonice method). You should put it immediately before the filesystem hook. Now proceed to regenerate your initramfs :<br />
<br />
# mkinitcpio -k `uname -r` -g /boot/kernel26.img<br />
<br />
You need to adjust this command according to the kernel you plan to use and the name of the initramfs in the grub configuration. Anyway you should not need to modify anything in the grub configuration.<br />
<br />
==Support for encryption==<br />
The package in the AUR does already support encryption. You need to:<br />
* generate a key with the suspend-keygen utility included in the uswsusp package;<br />
* write the name of the key in /etc/suspend.conf;<br />
* uncomment or add the following line in /etc/suspend.conf<br />
<br />
encrypt = y<br />
RSA key file = <path_to_keyfile><br />
* build a new initramfs with the uresume hook just before the filesystem one.<br />
<br />
==Support for splash screens and suspension to file==<br />
<br />
The AUR package does not provide support for splash screens: uswsusp would support splashy and fbsplash, but you need to modify the PKGBUILD in order to recompile uswsusp with libsplashy or fbsplash support: see the HOWTO and README in the source tarball for details.<br />
<br />
Please note that uswsusp can also suspend to a file, but only if you use an experimental mm-patched kernel. If you want to suspend to file, tuxonice is probably the way to go. In the case you like experimental things, see the instructions in the HOWTO of the uswsusp source tarball.<br />
<br />
==Suspending==<br />
<br />
Now you could try to suspend directly calling s2disk from the command line:<br />
<br />
# s2disk<br />
<br />
However, this is highly likely to fail, because some services could need to be stopped, some modules unloaded, etc. Thus it is probably necessary to resort to a userspace tool which calls internally s2disk. The hibernate-script does this. See [[Suspend to Disk#Editing /etc/hibernate/hibernate.conf|below]] about details for defining the ususpend-disk method as default in /etc/hibernate/hibernate.conf. For the moment being, remember that you can define specific options in /etc/hibernate/ususpend-disk.conf and, after having configured also /etc/hibernate/common.conf, you can suspend to disk with the uswsusp method with the following command:<br />
<br />
# hibernate -F /etc/hibernate/ususpend-disk.conf <br />
<br />
=Tuxonice method=<br />
<br />
==Obtaining tuxonice==<br />
Tuxonice consists of a kernel patch, plus a user interface. Only the kernel patch is necessary, the user interface provides merely a semi-graphical interface displayed during the hibernation/resume cycle. <br />
<br />
Archlinux used to deliver a binary tuxonice-patched kernel, but none of the devs want currently to maintain it. <br />
<br />
However you can use the kernel26tuxonice in AUR unsupported. It automatizes all the patch routine, the compilation and installation of the kernel, the regeneration of the initramfs with an appropriate hook. <br />
<br />
Otherwise, you need to patch, configure and compile your own kernel. You can do this either with the ABS method (starting from the arch default kernel PKGBUILD and adding the tuxonice patchset, or with the plain, old, reliable, venerable routine of <br />
<br />
# make menuconfig<br />
# make<br />
# make modules_install<br />
# cp arch/i386/boot/bzImage /boot/kernel-tuxonice-2.6.*<br />
<br />
See [[Kernel Compilation From Source]] and [[Kernel Compilation with ABS]] for instructions.<br />
In both cases, you need to configure the options added by the patchset, which you can find in the ACPI section of make menuconfig. Anyway, the defaults should be suitable for the large majority of scenarios. You can also hardcode in the kernel the path of your swap partition. In this case you can skip the below [[Suspend to Disk#Editing the Grub menu.lst]] .<br />
<br />
Please note that, if you spend the time to reconfigure completely the kernel (and in particular if you compile into the kernel the stuff necessary to boot your machine), you can be dispensed by the necessity to generate and use an initramfs: tuxonice will be able to resume properly also without an initrd/initramfs.<br />
<br />
==Editing the Grub menu.lst==<br />
Before your can use the suspend function, you need to boot your computer with the "resume" parameter, unless you have hardcoded your swap partition during the kernel configuration. The resume parameter points to the swap partition or swap file. The parameter is a kernel boot parameter, that is it should be added, if you use GRUB, to the line of /boot/grub/menu.lst where the location of your kernel is specified. <br />
For example:<br />
<br />
# tuxonice kernel<br />
title ArchLinux<br />
kernel /boot/kernel-tuxonice-2.6 root=/dev/hda2 resume=swap:/dev/hda3<br />
initrd /boot/tuxonice.img<br />
<br />
This assumes that you installed Archlinux onto the second hard drive partition, that your swap partition is the third, that you have not a separate /boot partition and that you are using an initrd. Adjust accordingly to your case.<br />
<br />
==Recreating the initramfs==<br />
<br />
If you use an initramfs, you need to add the tuxonice hook (which is different from the uresume used by uswsusp and by the resume hook for vanilla kernel suspension) in the HOOKS in the configuration of mkinitcpio. The hook is provided by the tuxoniceinitcpio package in AUR unsupported. This package is a dependency of kernel26tuxonice and is applied by default by kernel26tuxonice. Once you have added the tuxonice hook, you need to regenerate your initramfs, with a command like the following:<br />
<br />
# mkinitcpio -k kernel-tuxonice-2.6 -g /boot/tuxonice.img<br />
<br />
==Using userui - a user interface for tuxonice==<br />
<br />
Optionally, you can use a text or fbsplash interface with a progress bar with tuxonice. To do this, install the userui package in the extra repo:<br />
<br />
# pacman -S userui<br />
<br />
In ''/etc/hibernate/suspend2.conf'', configure the user interface:<br />
<br />
## Specify a userui like this:<br />
# text interface<br />
ProcSetting user_interface/program /usr/sbin/tuxoniceui_text<br />
<br />
or<br />
<br />
## Specify a userui like this:<br />
# fbsplash interface interface<br />
ProcSetting user_interface/program /usr/sbin/tuxoniceui_fbsplash<br />
<br />
The ''fbsplash'' interface also needs a fbsplash theme in ''/etc/splash/suspend2/''.<br />
<br />
The text interface may be good for debugging suspend2, as it displays some messages.<br />
You won't see a user interface for the first few seconds of the resume process unless you add the ''userui'' hook to your mkinitcpio configuration and regenerate your initramfs, but this is also optional.<br />
<br />
==Suspending and Resuming==<br />
<br />
Now you need to tweak the hibernate script. See [[Suspend to Disk#Editing /etc/hibernate/hibernate.conf|below]] for instructions about defining the tuxonice method as the default hibernation method. <br />
The specific file is /etc/hibernate/suspend2.conf (the hibernate-script still uses the old name of tuxonice):<br />
<br />
Make sure that the following lines are uncommented and appropriately configured:<br />
UseSuspend2 yes<br />
Reboot no<br />
EnableEscape yes<br />
DefaultConsoleLevel 1<br />
Compressor lzf<br />
<br />
Encryptor none<br />
<br />
Once you have tweaked what you want/need (also in /etc/hibernate/common.conf), you can try tuxonice hibernation with the following method:<br />
<br />
# hibernate -F /etc/hibernate/suspend2.conf<br />
<br />
You can abort a suspend cycle if you press the escape key. If you press a capital r, you will force the system to reboot after hibernation.<br />
If all goes well, you should be able to resume using the same Grub menu selection. If you make that option the default for Grub, you will always default to resuming if a resume image is available. '''Do never use a different kernel to resume than you used to suspend! If pacman updates your kernel, don't suspend before you have rebooted properly.''' It is recommended that you test the suspend/hibernate from a text console first and then once you have confirmed that it works try it from within X.<br />
<br />
You can make this practice safer adding the hibernate-cleanup service to your SERVICES array in /etc/rc.conf. This script will make sure that any stale image is deleted from your swap partition at boot time. This should make your system safe also in the case that you have chosen the mistaken kernel at the grub prompt. The hibernate-cleanup service is included in the hibernate-script package.<br />
<br />
== References ==<br />
<br />
*The [http://www.tuxonice.net tuxonice website] and the [http://wiki.tuxonice.net/ tuxonice wiki] are excellent sources of documentation.<br />
*There is a good [http://gentoo-wiki.com/HOWTO_Software_Suspend_v2 Gentoo wiki article] that covers a lot of the same material.<br />
<br />
<br />
=Hibernate tricks with the hibernate.script=<br />
<br />
This is a brief overview of the hibernate script. If you want to tweak it further, examine the ''common.conf'' and ''suspend2.conf'' files further and read the excellent and exhaustive man pages for hibernate and hibernate.conf.<br />
<br />
==Editing /etc/hibernate/hibernate.conf==<br />
<br />
In order to call directly the hibernate command without the -F option, you need to define your preferred hibernation method. This should be done in this file. If you list several methods, the first one will be used. Note that ''hibernate'' can also be used with [[Suspend to RAM]] or vanilla swsusp, but this is not part of this HOWTO).<br />
<br />
Then either:<br />
<br />
TryMethod ususpend-disk.conf<br />
<br />
or: <br />
<br />
TryMethod suspend2.conf<br />
<br />
==Editing /etc/hibernate/common.conf==<br />
<br />
The options in this file are used with any hibernation method (actually, the file is sourced by the configuration files of each method) and also by [[Suspend to RAM]] when accomplished with the hibernate-script. This file is complex and well commented. The man page hibernate.conf describes adequately all the options. Here, we can only stress the most commonly useful parts.<br />
<br />
Uncomment the lines for any filesystems that have the potential to change while your computer is suspended (for example shared partitions with windows like vfat or ntfs ones). They will be remounted upon resume. Otherwise you would risk corrupting the filesystems.<br />
<br />
### filesystems<br />
# Unmount /nfsshare /windows /mnt/sambaserver<br />
# UnmountFSTypes smbfs nfs<br />
# UnmountGraceTime 1<br />
# Mount /windows<br />
<br />
If you don't explicitly restore the volume levels, ALSA may have the sound channels muted after resuming. If this happens, look for<br />
<br />
### services<br />
<br />
in /etc/hibernate/common.conf and change the line just below to<br />
<br />
RestartServices alsa<br />
<br />
The alsa service will be stopped before suspension and restarted after resuming: the sound channels and volumes will be as before.<br />
You may want to restart other problematic services here.<br />
<br />
A common issue is that some drivers do not support suspension, that is they do not work properly after a suspension cycle or even they prevent the system from suspending or resuming properly. <br />
In these cases (which should be reported - at least for modules in the vanilla kernel - to the suspend-devel@lists.sourceforge.net mailing list, so that they can be fixed upstream) you can unload the module before suspension and reload it after resuming: the hibernate-script can automatize this routine with the LoadModules and UnloadModules options. Actually, the hibernate-script already unload some problematic modules, listed in /etc/hibernate/blacklisted-modules, so you can also add the modules in that file.<br />
<br />
<br />
To re-connect to networks after rebooting, you may want to add<br />
OnResume 25 netcfg2 -a<br />
OnResume 20 netcfg-auto-wireless <your-network-interface><br />
This will disconnect from all networks, then should automatically choose the correct one. If you use another way to connect to a network (such as netcfg2 <profile-name> then of-course, put that there instead.<br />
<br />
If you need/want to eject all PcCards before suspending and reinsert them after resuming, change the ''EjectCards'' setting in ''common.conf'':<br />
<br />
### pcmcia<br />
EjectCards yes<br />
<br />
This is necessary on some laptops, if the pccards stop working after resume.<br />
<br />
Finally, the most problematic aspect is constituted by the video card: its status needs often to be restored after resuming. In other cases, it is necessary to switch from X to the console.<br />
The following options in /etc/hibernate/common.conf will probably fix these issues (whose symptom could be a frozen machine or only a black display after resuming):<br />
<br />
### vbetool<br />
#EnableVbetool yes<br />
#RestoreVbeStateFrom /var/lib/vbetool/vbestate<br />
#VbetoolPost yes<br />
# RestoreVCSAData yes<br />
<br />
### xhacks<br />
#SwitchToTextMode yes<br />
#UseDummyXServer yes<br />
#DummyXServerConfig xorg-dummy.conf<br />
<br />
You can uncomment one or many of them in order to see if the problem is solved. In order to use the first block of options, you need to install the vbetool package from the extra repository. Each of the option is documented in man hibernate.conf. <br />
Please note that it is very important to try all the different combinations of these options before than anything else, becaause the problems with the display are the most common source of troubles in a suspension cycle.<br />
<br />
== NVidia specific settings ==<br />
If you have an NVidia graphics card and are using the binary driver by NVidia with an AGP card, you have to add the following line to your /etc/X11/xorg.conf:<br />
<br />
Option "NvAGP" "1"<br />
<br />
NVidia also suggest this setting for the hibernate script:<br />
<br />
ProcSetting extra_pages_allowance 0<br />
<br />
to the file /etc/hibernate/common.conf. This setting also seems to help with the binary ATI driver. At last, you need to uncomment the nvidia module in /etc/hibernate/blacklisted-modules.<br />
<br />
== Suspending with fglrx ==<br />
Following addition to /etc/hibernate/suspend2.conf is required:<br />
<br />
# For fglrx<br />
ProcSetting extra_pages_allowance 20000<br />
<br />
== Dropping Disk Caches ==<br />
<br />
As a way to speed up suspending, you can free the memory used for disk caches. so there will be less to write to the disk. The downside is the risk of crashing your system. but I have had no trouble with it so far, while reducing the size of the suspended image by half. Just run this before hibernating:<br />
<br />
sync; echo 3 > /proc/sys/vm/drop_caches<br />
[http://www.linuxinsight.com/proc_sys_vm_drop_caches.html drop_caches introduction]<br />
<br />
=Combining suspend to disk with suspend to RAM=<br />
<br />
If your motherboard or laptop supports [[Suspend to RAM]], you can combine it with suspend2. This will result in the following behavior:<br />
<br />
* When you call hibernate, your system will suspend to disk and after that suspend to RAM instead of powering down.<br />
* When you turn your system back on, it will resume directly from RAM (which only takes a few seconds)<br />
* If your battery fails in the meantime (and the image in your memory is therefore lost), you will be able to resumes from disk.<br />
<br />
This can be done both with uswsusp and with tuxonice. <br />
<br />
With uswsusp, you should use s2both. You can also call s2both from the hibernate script (with all its richness of options), resorting to the ususepnd-both.conf method. Please note that s2both works only if s2ram (see [[Suspend to RAM]] works in your system. There is no way to force it to work if your laptop model is not whitelisted in s2ram. See [[Suspend to RAM]] for instructions about how to whitelist your laptop in the local copy of s2ram and how to report that your laptop suspend to ram properly so that it is whitelisted in the next uswsusp release.<br />
<br />
To do it with tuxonice, edit ''/etc/hibernate/suspend2.conf'':<br />
<br />
## Powerdown method - 3 for suspend-to-RAM, 4 for ACPI S4 sleep, 5 for poweroff<br />
PowerdownMethod 3<br />
<br />
For this to work, your computer must be able to use suspend to RAM also without s2ram.</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Hibernate-script&diff=37267Hibernate-script2008-02-17T22:24:54Z<p>Bavardage: Added bit about re-connecting to a nw</p>
<hr />
<div>[[Category:Power management (English)]]<br />
[[Category:Laptops (English)]]<br />
[[Category:HOWTOs (English)]]<br />
<br />
This article will describe how to suspend a computer (usually a laptop) to disk. This means that all the running processes will be saved to the hard drive and power will completely shut down. This article discusses the two main methods to accomplish this task, that is userspace suspension (uswsusp) and tuxonice (formerly known as suspend2). See the [http://suspend.sourceforge.net/ ususpend website] and the [http://www.tuxonice.net/ tuxonice website] for complete documentation. There is a third method: using the kernelspace functionalities of the vanilla kernel. However, this method is the least developed, the slowest and the less reliable. On the contrary, tuxonice and ususpend are competing in features and stability. The only method to decide which method is better for you is to try both of them. From a general point of view, we can say that uswsusp does not force you to patch, configure and compile a kernel, while tuxonice does. However, tuxonice can be used without an initrd/initramfs, while using ususpend without an initrd/initramfs is discouraged; moreover, tuxonice allows you to suspend on a regular file if you have not a swap partition, while uswsusp give this possibility only if you run an experimental and unstable mm kernel.<br />
<br />
It is important to distinguish the core method of suspension to disk from the userspace application which you use to hibernate your machine to disk. A userspace application is required because the large majority of the laptops require some quirks in order to accomplish a proficient, successful hibernation cycle: unloading modules, restarting services, unmount windows partitions and usb keys, and so on.<br />
<br />
There are two widely used userspace applications for this purpose: [[pm-utils]] and hibernate-script. You can find both of them in the extra repo. However, since in this guide we need to describe two different, competing core methods, we will focus on the hibernate-script, since only this script allows the user to choose the core method he prefers. On the contrary, [[pm-utils]], at least in the version actually distributed by arch, forces you silently to use the old vanilla method. On the other side, the script, developed by the tuxonice development team, can be used nonetheless also to hibernate your machine with the ususpend method, and even to suspend the machine to ram (actually it is an excellent tool also for this task, but we are not going to discuss this aspect in this document, see [[Suspend to RAM]]).<br />
<br />
If you prefer to use pm-utils, refer to the specific [[pm-utils|wiki article]].<br />
<br />
Thus:<br />
<br />
# pacman -S hibernate-script<br />
<br />
The discussion will be articulated in four parts. First of all, we will discuss the userspace method, secondly the tuxonice one, thirdly we will see how to use the power of the hibernate-script in order to circumvent some problems which could impair your ability to accomplish successful suspend/resume cycles. These last tips can be used with both methods. On the contrary, the first two parts will include instructions to use the hibernate-script in order to accomplish the basic operations with the two methods. In the fourth and last part, we will see how to combine suspension to disk and [[Suspend to RAM]] . <br />
<br />
When there is the need to modify the configuration of the bootloader, we will be always under the assumption that you use grub, but it should not be difficult to act analogously on the configuration of lilo.<br />
<br />
=Uswsusp method=<br />
<br />
The userspace method lets you resort to some advanced suspension abilities included in vanilla kernels > 2.6.17. You need two userspace tools, called s2disk and resume, which do what their names say. They are both included in the uswsusp package (which includes also s2ram, see [[Suspend to RAM]] ). You can find uswsusp in the AUR. The package in the AUR includes also an initramfs hook which allows you to resume properly using an initramfs.<br />
<br />
==Obtaining uswsusp==<br />
The first thing to do is to download the tarball from the AUR page. Compile the source and create the package with makepkg and install it with pacman -U.<br />
<br />
<br />
==Editing /etc/suspend.conf==<br />
On the contrary, you need to edit the s2disk configuration file, called /etc/suspend.conf. It is essential that you modify the resume device parameter:<br />
<br />
resume device = /dev/sda3<br />
<br />
It needs to point to your swap partition: in this case, the third partition of a primary pata-sata drive. It is also a good thing to enable compression, because this speeds up greatly your suspension/resume routine.<br />
<br />
Note that it is important that this configuration file be edited *before* recreating the initramfs (done below). Presently, the initramfs build process reads this configuration file, and embeds the current resume parameter. If not changed from the default '<path_to_resume_device_file>', this causes problems such as seeing, on bootup:<br />
<br />
# Could not stat the resume device file '<path_to_resume_device_file>'<br />
# Please type in the full path name to try again or press ENTER to boot the system.<br />
<br />
If you have experiencing this problem, simply edit the file as appropriate, and then rebuild the initramfs.<br />
<br />
==Recreate the intramfs==<br />
Now you need to recreate an initramfs with the new hook. So edit the /etc/mkinitcpio.conf file. In the HOOKS list add the uresume hook (it is different from the resume hook, which is on the contrary required by the tuxonice method). You should put it immediately before the filesystem hook. Now proceed to regenerate your initramfs :<br />
<br />
# mkinitcpio -k `uname -r` -g /boot/kernel26.img<br />
<br />
You need to adjust this command according to the kernel you plan to use and the name of the initramfs in the grub configuration. Anyway you should not need to modify anything in the grub configuration.<br />
<br />
==Support for encryption==<br />
The package in the AUR does already support encryption. You need to:<br />
* generate a key with the suspend-keygen utility included in the uswsusp package;<br />
* write the name of the key in /etc/suspend.conf;<br />
* uncomment or add the following line in /etc/suspend.conf<br />
<br />
encrypt = y<br />
RSA key file = <path_to_keyfile><br />
* build a new initramfs with the uresume hook just before the filesystem one.<br />
<br />
==Support for splash screens and suspension to file==<br />
<br />
The AUR package does not provide support for splash screens: uswsusp would support splashy and fbsplash, but you need to modify the PKGBUILD in order to recompile uswsusp with libsplashy or fbsplash support: see the HOWTO and README in the source tarball for details.<br />
<br />
Please note that uswsusp can also suspend to a file, but only if you use an experimental mm-patched kernel. If you want to suspend to file, tuxonice is probably the way to go. In the case you like experimental things, see the instructions in the HOWTO of the uswsusp source tarball.<br />
<br />
==Suspending==<br />
<br />
Now you could try to suspend directly calling s2disk from the command line:<br />
<br />
# s2disk<br />
<br />
However, this is highly likely to fail, because some services could need to be stopped, some modules unloaded, etc. Thus it is probably necessary to resort to a userspace tool which calls internally s2disk. The hibernate-script does this. See [[Suspend to Disk#Editing /etc/hibernate/hibernate.conf|below]] about details for defining the ususpend-disk method as default in /etc/hibernate/hibernate.conf. For the moment being, remember that you can define specific options in /etc/hibernate/ususpend-disk.conf and, after having configured also /etc/hibernate/common.conf, you can suspend to disk with the uswsusp method with the following command:<br />
<br />
# hibernate -F /etc/hibernate/ususpend-disk.conf <br />
<br />
=Tuxonice method=<br />
<br />
==Obtaining tuxonice==<br />
Tuxonice consists of a kernel patch, plus a user interface. Only the kernel patch is necessary, the user interface provides merely a semi-graphical interface displayed during the hibernation/resume cycle. <br />
<br />
Archlinux used to deliver a binary tuxonice-patched kernel, but none of the devs want currently to maintain it. <br />
<br />
However you can use the kernel26tuxonice in AUR unsupported. It automatizes all the patch routine, the compilation and installation of the kernel, the regeneration of the initramfs with an appropriate hook. <br />
<br />
Otherwise, you need to patch, configure and compile your own kernel. You can do this either with the ABS method (starting from the arch default kernel PKGBUILD and adding the tuxonice patchset, or with the plain, old, reliable, venerable routine of <br />
<br />
# make menuconfig<br />
# make<br />
# make modules_install<br />
# cp arch/i386/boot/bzImage /boot/kernel-tuxonice-2.6.*<br />
<br />
See [[Kernel Compilation From Source]] and [[Kernel Compilation with ABS]] for instructions.<br />
In both cases, you need to configure the options added by the patchset, which you can find in the ACPI section of make menuconfig. Anyway, the defaults should be suitable for the large majority of scenarios. You can also hardcode in the kernel the path of your swap partition. In this case you can skip the below [[Suspend to Disk#Editing the Grub menu.lst]] .<br />
<br />
Please note that, if you spend the time to reconfigure completely the kernel (and in particular if you compile into the kernel the stuff necessary to boot your machine), you can be dispensed by the necessity to generate and use an initramfs: tuxonice will be able to resume properly also without an initrd/initramfs.<br />
<br />
==Editing the Grub menu.lst==<br />
Before your can use the suspend function, you need to boot your computer with the "resume" parameter, unless you have hardcoded your swap partition during the kernel configuration. The resume parameter points to the swap partition or swap file. The parameter is a kernel boot parameter, that is it should be added, if you use GRUB, to the line of /boot/grub/menu.lst where the location of your kernel is specified. <br />
For example:<br />
<br />
# tuxonice kernel<br />
title ArchLinux<br />
kernel /boot/kernel-tuxonice-2.6 root=/dev/hda2 resume=swap:/dev/hda3<br />
initrd /boot/tuxonice.img<br />
<br />
This assumes that you installed Archlinux onto the second hard drive partition, that your swap partition is the third, that you have not a separate /boot partition and that you are using an initrd. Adjust accordingly to your case.<br />
<br />
==Recreating the initramfs==<br />
<br />
If you use an initramfs, you need to add the tuxonice hook (which is different from the uresume used by uswsusp and by the resume hook for vanilla kernel suspension) in the HOOKS in the configuration of mkinitcpio. The hook is provided by the tuxoniceinitcpio package in AUR unsupported. This package is a dependency of kernel26tuxonice and is applied by default by kernel26tuxonice. Once you have added the tuxonice hook, you need to regenerate your initramfs, with a command like the following:<br />
<br />
# mkinitcpio -k kernel-tuxonice-2.6 -g /boot/tuxonice.img<br />
<br />
==Using userui - a user interface for tuxonice==<br />
<br />
Optionally, you can use a text or fbsplash interface with a progress bar with tuxonice. To do this, install the userui package in the extra repo:<br />
<br />
# pacman -S userui<br />
<br />
In ''/etc/hibernate/suspend2.conf'', configure the user interface:<br />
<br />
## Specify a userui like this:<br />
# text interface<br />
ProcSetting user_interface/program /usr/sbin/tuxoniceui_text<br />
<br />
or<br />
<br />
## Specify a userui like this:<br />
# fbsplash interface interface<br />
ProcSetting user_interface/program /usr/sbin/tuxoniceui_fbsplash<br />
<br />
The ''fbsplash'' interface also needs a fbsplash theme in ''/etc/splash/suspend2/''.<br />
<br />
The text interface may be good for debugging suspend2, as it displays some messages.<br />
You won't see a user interface for the first few seconds of the resume process unless you add the ''userui'' hook to your mkinitcpio configuration and regenerate your initramfs, but this is also optional.<br />
<br />
==Suspending and Resuming==<br />
<br />
Now you need to tweak the hibernate script. See [[Suspend to Disk#Editing /etc/hibernate/hibernate.conf|below]] for instructions about defining the tuxonice method as the default hibernation method. <br />
The specific file is /etc/hibernate/suspend2.conf (the hibernate-script still uses the old name of tuxonice):<br />
<br />
Make sure that the following lines are uncommented and appropriately configured:<br />
UseSuspend2 yes<br />
Reboot no<br />
EnableEscape yes<br />
DefaultConsoleLevel 1<br />
Compressor lzf<br />
<br />
Encryptor none<br />
<br />
Once you have tweaked what you want/need (also in /etc/hibernate/common.conf), you can try tuxonice hibernation with the following method:<br />
<br />
# hibernate -F /etc/hibernate/suspend2.conf<br />
<br />
You can abort a suspend cycle if you press the escape key. If you press a capital r, you will force the system to reboot after hibernation.<br />
If all goes well, you should be able to resume using the same Grub menu selection. If you make that option the default for Grub, you will always default to resuming if a resume image is available. '''Do never use a different kernel to resume than you used to suspend! If pacman updates your kernel, don't suspend before you have rebooted properly.''' It is recommended that you test the suspend/hibernate from a text console first and then once you have confirmed that it works try it from within X.<br />
<br />
You can make this practice safer adding the hibernate-cleanup service to your SERVICES array in /etc/rc.conf. This script will make sure that any stale image is deleted from your swap partition at boot time. This should make your system safe also in the case that you have chosen the mistaken kernel at the grub prompt. The hibernate-cleanup service is included in the hibernate-script package.<br />
<br />
== References ==<br />
<br />
*The [http://www.tuxonice.net tuxonice website] and the [http://wiki.tuxonice.net/ tuxonice wiki] are excellent sources of documentation.<br />
*There is a good [http://gentoo-wiki.com/HOWTO_Software_Suspend_v2 Gentoo wiki article] that covers a lot of the same material.<br />
<br />
<br />
=Hibernate tricks with the hibernate.script=<br />
<br />
This is a brief overview of the hibernate script. If you want to tweak it further, examine the ''common.conf'' and ''suspend2.conf'' files further and read the excellent and exhaustive man pages for hibernate and hibernate.conf.<br />
<br />
==Editing /etc/hibernate/hibernate.conf==<br />
<br />
In order to call directly the hibernate command without the -F option, you need to define your preferred hibernation method. This should be done in this file. If you list several methods, the first one will be used. Note that ''hibernate'' can also be used with [[Suspend to RAM]] or vanilla swsusp, but this is not part of this HOWTO).<br />
<br />
Then either:<br />
<br />
TryMethod ususpend-disk.conf<br />
<br />
or: <br />
<br />
TryMethod suspend2.conf<br />
<br />
==Editing /etc/hibernate/common.conf==<br />
<br />
The options in this file are used with any hibernation method (actually, the file is sourced by the configuration files of each method) and also by [[Suspend to RAM]] when accomplished with the hibernate-script. This file is complex and well commented. The man page hibernate.conf describes adequately all the options. Here, we can only stress the most commonly useful parts.<br />
<br />
Uncomment the lines for any filesystems that have the potential to change while your computer is suspended (for example shared partitions with windows like vfat or ntfs ones). They will be remounted upon resume. Otherwise you would risk corrupting the filesystems.<br />
<br />
### filesystems<br />
# Unmount /nfsshare /windows /mnt/sambaserver<br />
# UnmountFSTypes smbfs nfs<br />
# UnmountGraceTime 1<br />
# Mount /windows<br />
<br />
If you don't explicitly restore the volume levels, ALSA may have the sound channels muted after resuming. If this happens, look for<br />
<br />
### services<br />
<br />
in /etc/hibernate/common.conf and change the line just below to<br />
<br />
RestartServices alsa<br />
<br />
The alsa service will be stopped before suspension and restarted after resuming: the sound channels and volumes will be as before.<br />
You may want to restart other problematic services here.<br />
<br />
A common issue is that some drivers do not support suspension, that is they do not work properly after a suspension cycle or even they prevent the system from suspending or resuming properly. <br />
In these cases (which should be reported - at least for modules in the vanilla kernel - to the suspend-devel@lists.sourceforge.net mailing list, so that they can be fixed upstream) you can unload the module before suspension and reload it after resuming: the hibernate-script can automatize this routine with the LoadModules and UnloadModules options. Actually, the hibernate-script already unload some problematic modules, listed in /etc/hibernate/blacklisted-modules, so you can also add the modules in that file.<br />
<br />
###Network<br />
To re-connect to networks after rebooting, you may want to add<br />
OnResume 25 netcfg2 -a<br />
OnResume 20 netcfg-auto-wireless <your-network-interface><br />
This will disconnect from all networks, then should automatically choose the correct one. If you use another way to connect to a network (such as netcfg2 <profile-name> then of-course, put that there instead.<br />
<br />
If you need/want to eject all PcCards before suspending and reinsert them after resuming, change the ''EjectCards'' setting in ''common.conf'':<br />
<br />
### pcmcia<br />
EjectCards yes<br />
<br />
This is necessary on some laptops, if the pccards stop working after resume.<br />
<br />
Finally, the most problematic aspect is constituted by the video card: its status needs often to be restored after resuming. In other cases, it is necessary to switch from X to the console.<br />
The following options in /etc/hibernate/common.conf will probably fix these issues (whose symptom could be a frozen machine or only a black display after resuming):<br />
<br />
### vbetool<br />
#EnableVbetool yes<br />
#RestoreVbeStateFrom /var/lib/vbetool/vbestate<br />
#VbetoolPost yes<br />
# RestoreVCSAData yes<br />
<br />
### xhacks<br />
#SwitchToTextMode yes<br />
#UseDummyXServer yes<br />
#DummyXServerConfig xorg-dummy.conf<br />
<br />
You can uncomment one or many of them in order to see if the problem is solved. In order to use the first block of options, you need to install the vbetool package from the extra repository. Each of the option is documented in man hibernate.conf. <br />
Please note that it is very important to try all the different combinations of these options before than anything else, becaause the problems with the display are the most common source of troubles in a suspension cycle.<br />
<br />
== NVidia specific settings ==<br />
If you have an NVidia graphics card and are using the binary driver by NVidia with an AGP card, you have to add the following line to your /etc/X11/xorg.conf:<br />
<br />
Option "NvAGP" "1"<br />
<br />
NVidia also suggest this setting for the hibernate script:<br />
<br />
ProcSetting extra_pages_allowance 0<br />
<br />
to the file /etc/hibernate/common.conf. This setting also seems to help with the binary ATI driver. At last, you need to uncomment the nvidia module in /etc/hibernate/blacklisted-modules.<br />
<br />
== Suspending with fglrx ==<br />
Following addition to /etc/hibernate/suspend2.conf is required:<br />
<br />
# For fglrx<br />
ProcSetting extra_pages_allowance 20000<br />
<br />
== Dropping Disk Caches ==<br />
<br />
As a way to speed up suspending, you can free the memory used for disk caches. so there will be less to write to the disk. The downside is the risk of crashing your system. but I have had no trouble with it so far, while reducing the size of the suspended image by half. Just run this before hibernating:<br />
<br />
sync; echo 3 > /proc/sys/vm/drop_caches<br />
[http://www.linuxinsight.com/proc_sys_vm_drop_caches.html drop_caches introduction]<br />
<br />
=Combining suspend to disk with suspend to RAM=<br />
<br />
If your motherboard or laptop supports [[Suspend to RAM]], you can combine it with suspend2. This will result in the following behavior:<br />
<br />
* When you call hibernate, your system will suspend to disk and after that suspend to RAM instead of powering down.<br />
* When you turn your system back on, it will resume directly from RAM (which only takes a few seconds)<br />
* If your battery fails in the meantime (and the image in your memory is therefore lost), you will be able to resumes from disk.<br />
<br />
This can be done both with uswsusp and with tuxonice. <br />
<br />
With uswsusp, you should use s2both. You can also call s2both from the hibernate script (with all its richness of options), resorting to the ususepnd-both.conf method. Please note that s2both works only if s2ram (see [[Suspend to RAM]] works in your system. There is no way to force it to work if your laptop model is not whitelisted in s2ram. See [[Suspend to RAM]] for instructions about how to whitelist your laptop in the local copy of s2ram and how to report that your laptop suspend to ram properly so that it is whitelisted in the next uswsusp release.<br />
<br />
To do it with tuxonice, edit ''/etc/hibernate/suspend2.conf'':<br />
<br />
## Powerdown method - 3 for suspend-to-RAM, 4 for ACPI S4 sleep, 5 for poweroff<br />
PowerdownMethod 3<br />
<br />
For this to work, your computer must be able to use suspend to RAM also without s2ram.</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Laptop&diff=37266Laptop2008-02-17T22:21:02Z<p>Bavardage: /* Networkmanager */</p>
<hr />
<div>[[Category:HOWTOs (English)]]<br />
[[Category:Laptops (English)]]<br />
<br />
This page should contain links to pages needed for configuring a laptop for the best experience.<br />
<br />
= Cpufrequtils =<br />
<br />
[[Cpufrequtils]] is a CPU Frequency Scaling, a technology used primarily by notebooks which enables the OS to scale the CPU speed up or down, depending on the current system load and/or power scheme.<br />
<br />
= Pm-utils =<br />
[[Pm-utils]] is suspend and powerstate setting framework.<br />
<br />
= Networkmanager =<br />
[[Networkmanager]] provides automatic network detection and configuration for the system.<br />
<br />
Note: this is being phased out in favor of [[network_profiles]]<br />
<br />
= Lapsus =<br />
[[Asus_G1#The_Lapsus_daemon_.26_KDE_applet|Lapsus]] is a set of programs providing easy access to many features of various laptops. It currently supports most features provided by asus-laptop kernel module from ACPI4Asus project, such as additional LEDs, hotkeys, backlight control etc. It also has support for some IBM laptops features provided by IBM ThinkPad ACPI Extras Driver and NVRAM device.</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Laptop&diff=37265Laptop2008-02-17T22:20:06Z<p>Bavardage: /* Networkmanager */</p>
<hr />
<div>[[Category:HOWTOs (English)]]<br />
[[Category:Laptops (English)]]<br />
<br />
This page should contain links to pages needed for configuring a laptop for the best experience.<br />
<br />
= Cpufrequtils =<br />
<br />
[[Cpufrequtils]] is a CPU Frequency Scaling, a technology used primarily by notebooks which enables the OS to scale the CPU speed up or down, depending on the current system load and/or power scheme.<br />
<br />
= Pm-utils =<br />
[[Pm-utils]] is suspend and powerstate setting framework.<br />
<br />
= Networkmanager =<br />
[[Networkmanager]] provides automatic network detection and configuration for the system.<br />
<br />
Note: this is being phased out in favor of [[netcfg2]]<br />
<br />
= Lapsus =<br />
[[Asus_G1#The_Lapsus_daemon_.26_KDE_applet|Lapsus]] is a set of programs providing easy access to many features of various laptops. It currently supports most features provided by asus-laptop kernel module from ACPI4Asus project, such as additional LEDs, hotkeys, backlight control etc. It also has support for some IBM laptops features provided by IBM ThinkPad ACPI Extras Driver and NVRAM device.</div>Bavardagehttps://wiki.archlinux.org/index.php?title=HP_530&diff=37199HP 5302008-02-15T23:33:54Z<p>Bavardage: /* To Do */</p>
<hr />
<div>[[Category:Laptops (English)]]<br />
[[Category:HOWTOs (English)]]<br />
{{stub}}<br />
<br />
==Introduction==<br />
I was looking for a cheap, good bang for the buck laptop I could take back and forth to class and also something I could play with Linux on outside of desktop/workstation boxes. I browsed NewEgg for a few weeks looking for good deals and finally settled on this one. There were two versions, one was a Celeron with 512MB RAM and about the time I settled on it, the price of this one dropped so I went ahead and spent the extra for a Core Duo, double the RAM and a DVD burner.<br />
<br />
==Specs==<br />
It's a pretty run of the mill low end laptop. Nothing too fancy or too expensive .. here are the highlights.<br />
<br />
*Model 530 (GU337AT#ABA)<br />
*Screen 15.4" WXGA<br />
*Memory Size 1GB DDR2<br />
*Hard Disk 80GB<br />
*Optical Drive DVD±R/RW<br />
*Graphics Card Intel GMA950<br />
*Video Memory shared memory<br />
*CPU Type Intel Core Duo<br />
*CPU Speed T2300E(1.66GHz)<br />
*CPU FSB 667MHz<br />
*CPU L2 Cache 2MB<br />
*Resolution 1280 x 800<br />
*GPU/VPU Intel GMA950<br />
*Video Memory Up to 224-MB shared system memory<br />
*Graphic Type Integrated Card<br />
*HD Interface SATA<br />
*Memory Slots 2 x SO-DIMM<br />
*Memory Speed DDR2 667<br />
<br />
==Installation==<br />
The base install was extremely easy. Coming from Slackware I had a pretty good grasp of a text-based installer so I was right at home during the initial configuration. However, since this was my first experience with Arch I was a bit lost when it came time to configure the system. :^) I browsed the wiki here for a bit until I stumbled on the great [[Beginners_Guide|Beginners Guide]] which I used to update the system, grab Xorg, XFCE and pretty much everything else it mentioned. If you're an Arch newb like I am I strongly suggest browsing over there and checking out that Intro, I can't recommend it enough. :-)<br />
===Initial===<br />
Combine the fact I was coming to Arch from Slack with my OCD nature, I ended up with a the following partitioning scheme. <br />
<br />
/dev/sda6 /boot<br />
/dev/sda7 /<br />
/dev/sda8 /usr<br />
/dev/sda9 /home<br />
/dev/sda10 /var<br />
/dev/sda11 /tmp<br />
<br />
With a 2048MB SWAP space (2*1024RAM)<br />
<br />
===Post Install Config===<br />
I pretty much went down the aforementioned [[Beginners_Guide|Beginners Guide]] following the first reboot, so I won't go into a great deal of detail. Besides everyone has their own preferences on a lot of that stuff like media players and themes, fonts etc. <br />
<br />
I updated via pacman then grabbed the Xorg, sound (alsa), XFCE and fonts packages mentioned there. Then I configured DBUS and HAL which were pretty much working out of the box and edited /etc/rc.conf to load the DAEMONS and MODULES I needed. Everything worked on the first try with little or no tweaking needed so I was up and running my first fully functional Arch install. :-)<br />
<br />
==Issues==<br />
I only had three real issues during the install -- wireless, CPU frequency scaling and the (prevalent?) Linux + Laptop problem of the internal speaker not being muted when headphones are plugged in. I'll tackle them in order of severity.<br />
===Wireless===<br />
A laptop without wireless is pretty useless, and this is one of the areas Linux hasn't really shined in the past so I was a bit apprehensive when my wireless didn't work right out of the box. However after reading through most of the documentation on the Wiki and the Forums I got it working, so there is hope if you're struggling with it too.<br />
<br />
If you haven't already, take a look at the [[Wireless_Setup|wireless setup]] page. It's a good starting point/intro for wireless newbs like me. On there it mentions the method I use here as being the "non-preferred" method, but I couldn't get the "preferred" method there to work. Now that I know a little bit more about the process I may try to go back and look into it, but as long as it's not broken, I'm reluctant to "fix" it. :-/<br />
<br />
=====Hardware/Kernel Stuff=====<br />
First I grabbed the wireless tools package.<br />
pacman -S wireless_tools<br />
<br />
Then I figured out which type of card I had with lshwd (I actually had to grab lshwd with pacman first, but no biggie there!)<br />
lshwd<br />
.<br />
.<br />
10:00.0 Class 0280: Intel Corporation|PRO/Wireless 3945ABG (ipw3945)<br />
.<br />
.<br />
<br />
So, I need the ipw3945 module which was already on my system, as determined by:<br />
modinfo ipw3945<br />
<br />
I checked to see if it was loaded already<br />
lsmod | grep 3945<br />
<br />
It wasn't, but the iwl3945 ''was'' so I removed it. (At this point I had installed so many different modules and packages trying to get wireless to work I'm not sure exactly what comes pre-loaded with the default install so YMMV on this next little bit).<br />
rmmod iwl3945<br />
<br />
Then I dropped in the ipw3945 module<br />
modprobe ipw3945<br />
<br />
Finally I needed to insert the ipw3945 module (and remove any iwl3945) into the MODULES array in /etc/rc.conf and ipw3945d daemon into the DAEMONS array in the same file. I'm not sure if it matters, but I made sure I put the daemon before all the other networking related daemons, again, YMMV slightly.<br />
<br />
At this point you should have everything ready to go on the hardware side. You man want to reboot to make sure you got all the stuff in /etc/rc.conf correct since I thought I had things working a couple times until I rebooted then everything magically broke again. :^)<br />
<br />
=====Software/User Space Stuff=====<br />
(NOTE: I'm not endorsing one program/utility over another here, I'm just sharing what I got to work. :-) )<br />
I browsed around the Arch site here and Google looking for a nice wireless connection utility and tried a couple different things. I tried [[Networkmanager|networkmanager]] but that didn't really get me anywhere. Then I tried [[Wicd|wicd]] and it had all the features I needed and seemed to work alright so I went with it. I pretty much followed the procedure on the [[Wicd|wicd]] page and I was up and running in no time. I added wicd to my DAEMON array in /etc/rc.conf and launched it via the tray icon and it found my wireless connection ... and six of my neighbors connections too. :^)<br />
<br />
=====Summary=====<br />
Basically I had no idea how to do wireless on any platform when I started. This section isn't really intended to be a guide on how you ''SHOULD'' do things, rather an electronic form of my notes on how I ''DID'' do things. :-)<br />
<br />
===CPU Frequency Scaling===<br />
DISCLAIMER: I'm still not entirely sure I've got this working like it should but I can watch the little Applet I put on my Panel change from 1GHz to 1.67GHz when I launch apps so I'm satisfied that it's at least doing ''something'' for the time being. :^)<br />
<br />
Again, I refer you to the [[Beginners_Guide#Configuring_CPU_frequency_scaling|Beginners Guide]] as a starting point. I have an Intel based machine so I also relied heavily on the [[SpeedStep|SpeedStep]] guide. I got the cpudyn method to work best so that's what I've stuck with so far. Nothing really exciting here, I followed the guides mentioned and then added the appropriate daemons in the DAEMONS array in /etc/rc.conf.<br />
<br />
I also ended up with acpi_cpufreq, cpufreq_userspace and cpufreq_ondemand modules in my MODULES array in /etc/rc.conf after my failed attempts to get frequency scaling to work. I'm not sure if that's necessary or if it's even advisable but it hasn't broken my system yet so I've just left them alone.<br />
<br />
===Sound and Headphones===<br />
The issue with the sound wasn't the sound itself (well, actually it was, the internal speaker sucks :^) ) but the (apparently?) widespread problem of said speakers not being muted when headphones are plugged in. My Googling brought me seemingly endless solutions to this problem which didn't work .. these were some of my favorites:<br />
<br />
* Consider it a feature!<br />
* Just cut the wires to the internal speaker.<br />
* Don't do anything that needs sound.<br />
<br />
Well I really don't want to annoy everyone within earshot, void my warranty or sit in silence while hacking out programs at the last minute so the following are a largely hodge-podge conglomeration of "solutions" I found. I'm not sure if any one of these did it or the combination of them all, but, again, it works so I'm not going to touch it!<br />
<br />
* Grab alsa plugins (which I already I had IIRC)<br />
pacman -S alsa-plugin<br />
<br />
* Grab jack-audio-connection-kit (kind of makes sense from the name I guess?)<br />
pacman -S jack-audio-connection-kit<br />
<br />
* Then on some of the forums for other distros I saw a lot of suggestions to edit /etc/modprobe.conf in some form or fashion. Here's what mine looks like now and everything seems to work so I've just left it.<br />
options snd-hda-intel model=auto<br />
<br />
==Alternate Solution?==<br />
* I managed to get the headphones muting properly by adding this line to /etc/modprobe.conf<br />
options snd-hda-intel model=laptop<br />
<br />
==To Do==<br />
There are still a few things I'd like to get working at some point so if anyone is reading this and has any suggestions I'd love to hear them. :-) Most are pretty low priority/eye candy type stuff.<br />
<br />
*I'd like to have something like MacBooks where they "gradually" dim when idle as opposed to "entirely on" and "entirely off". I think that would come in handy when I just have my notebook open as a reference or something where I could still read it but not need it sitting there sucking my battery dry at full illumination. <br />
xbacklight -set 30 -time 60000 <--dim over a minute<br />
*Anything to extend battery life. I haven't really looked into it but I'd like to find a way to scale the core voltage as well as frequency. I've seen Intel utilities that can do that on Windows desktops but nothing so far for Linux<br />
*A way to kill the wireless card in software. This notebook comes with a button right by the power button to kill the wireless. It's not a big deal to hit the button I guess but it would be pretty neat if there was a way to simulate hitting the button in case I forget or I lose wireless connection for extended periods. I'm not even sure if this is possible or how it could be done, though.</div>Bavardagehttps://wiki.archlinux.org/index.php?title=HP_530&diff=37198HP 5302008-02-15T23:33:30Z<p>Bavardage: /* To Do */</p>
<hr />
<div>[[Category:Laptops (English)]]<br />
[[Category:HOWTOs (English)]]<br />
{{stub}}<br />
<br />
==Introduction==<br />
I was looking for a cheap, good bang for the buck laptop I could take back and forth to class and also something I could play with Linux on outside of desktop/workstation boxes. I browsed NewEgg for a few weeks looking for good deals and finally settled on this one. There were two versions, one was a Celeron with 512MB RAM and about the time I settled on it, the price of this one dropped so I went ahead and spent the extra for a Core Duo, double the RAM and a DVD burner.<br />
<br />
==Specs==<br />
It's a pretty run of the mill low end laptop. Nothing too fancy or too expensive .. here are the highlights.<br />
<br />
*Model 530 (GU337AT#ABA)<br />
*Screen 15.4" WXGA<br />
*Memory Size 1GB DDR2<br />
*Hard Disk 80GB<br />
*Optical Drive DVD±R/RW<br />
*Graphics Card Intel GMA950<br />
*Video Memory shared memory<br />
*CPU Type Intel Core Duo<br />
*CPU Speed T2300E(1.66GHz)<br />
*CPU FSB 667MHz<br />
*CPU L2 Cache 2MB<br />
*Resolution 1280 x 800<br />
*GPU/VPU Intel GMA950<br />
*Video Memory Up to 224-MB shared system memory<br />
*Graphic Type Integrated Card<br />
*HD Interface SATA<br />
*Memory Slots 2 x SO-DIMM<br />
*Memory Speed DDR2 667<br />
<br />
==Installation==<br />
The base install was extremely easy. Coming from Slackware I had a pretty good grasp of a text-based installer so I was right at home during the initial configuration. However, since this was my first experience with Arch I was a bit lost when it came time to configure the system. :^) I browsed the wiki here for a bit until I stumbled on the great [[Beginners_Guide|Beginners Guide]] which I used to update the system, grab Xorg, XFCE and pretty much everything else it mentioned. If you're an Arch newb like I am I strongly suggest browsing over there and checking out that Intro, I can't recommend it enough. :-)<br />
===Initial===<br />
Combine the fact I was coming to Arch from Slack with my OCD nature, I ended up with a the following partitioning scheme. <br />
<br />
/dev/sda6 /boot<br />
/dev/sda7 /<br />
/dev/sda8 /usr<br />
/dev/sda9 /home<br />
/dev/sda10 /var<br />
/dev/sda11 /tmp<br />
<br />
With a 2048MB SWAP space (2*1024RAM)<br />
<br />
===Post Install Config===<br />
I pretty much went down the aforementioned [[Beginners_Guide|Beginners Guide]] following the first reboot, so I won't go into a great deal of detail. Besides everyone has their own preferences on a lot of that stuff like media players and themes, fonts etc. <br />
<br />
I updated via pacman then grabbed the Xorg, sound (alsa), XFCE and fonts packages mentioned there. Then I configured DBUS and HAL which were pretty much working out of the box and edited /etc/rc.conf to load the DAEMONS and MODULES I needed. Everything worked on the first try with little or no tweaking needed so I was up and running my first fully functional Arch install. :-)<br />
<br />
==Issues==<br />
I only had three real issues during the install -- wireless, CPU frequency scaling and the (prevalent?) Linux + Laptop problem of the internal speaker not being muted when headphones are plugged in. I'll tackle them in order of severity.<br />
===Wireless===<br />
A laptop without wireless is pretty useless, and this is one of the areas Linux hasn't really shined in the past so I was a bit apprehensive when my wireless didn't work right out of the box. However after reading through most of the documentation on the Wiki and the Forums I got it working, so there is hope if you're struggling with it too.<br />
<br />
If you haven't already, take a look at the [[Wireless_Setup|wireless setup]] page. It's a good starting point/intro for wireless newbs like me. On there it mentions the method I use here as being the "non-preferred" method, but I couldn't get the "preferred" method there to work. Now that I know a little bit more about the process I may try to go back and look into it, but as long as it's not broken, I'm reluctant to "fix" it. :-/<br />
<br />
=====Hardware/Kernel Stuff=====<br />
First I grabbed the wireless tools package.<br />
pacman -S wireless_tools<br />
<br />
Then I figured out which type of card I had with lshwd (I actually had to grab lshwd with pacman first, but no biggie there!)<br />
lshwd<br />
.<br />
.<br />
10:00.0 Class 0280: Intel Corporation|PRO/Wireless 3945ABG (ipw3945)<br />
.<br />
.<br />
<br />
So, I need the ipw3945 module which was already on my system, as determined by:<br />
modinfo ipw3945<br />
<br />
I checked to see if it was loaded already<br />
lsmod | grep 3945<br />
<br />
It wasn't, but the iwl3945 ''was'' so I removed it. (At this point I had installed so many different modules and packages trying to get wireless to work I'm not sure exactly what comes pre-loaded with the default install so YMMV on this next little bit).<br />
rmmod iwl3945<br />
<br />
Then I dropped in the ipw3945 module<br />
modprobe ipw3945<br />
<br />
Finally I needed to insert the ipw3945 module (and remove any iwl3945) into the MODULES array in /etc/rc.conf and ipw3945d daemon into the DAEMONS array in the same file. I'm not sure if it matters, but I made sure I put the daemon before all the other networking related daemons, again, YMMV slightly.<br />
<br />
At this point you should have everything ready to go on the hardware side. You man want to reboot to make sure you got all the stuff in /etc/rc.conf correct since I thought I had things working a couple times until I rebooted then everything magically broke again. :^)<br />
<br />
=====Software/User Space Stuff=====<br />
(NOTE: I'm not endorsing one program/utility over another here, I'm just sharing what I got to work. :-) )<br />
I browsed around the Arch site here and Google looking for a nice wireless connection utility and tried a couple different things. I tried [[Networkmanager|networkmanager]] but that didn't really get me anywhere. Then I tried [[Wicd|wicd]] and it had all the features I needed and seemed to work alright so I went with it. I pretty much followed the procedure on the [[Wicd|wicd]] page and I was up and running in no time. I added wicd to my DAEMON array in /etc/rc.conf and launched it via the tray icon and it found my wireless connection ... and six of my neighbors connections too. :^)<br />
<br />
=====Summary=====<br />
Basically I had no idea how to do wireless on any platform when I started. This section isn't really intended to be a guide on how you ''SHOULD'' do things, rather an electronic form of my notes on how I ''DID'' do things. :-)<br />
<br />
===CPU Frequency Scaling===<br />
DISCLAIMER: I'm still not entirely sure I've got this working like it should but I can watch the little Applet I put on my Panel change from 1GHz to 1.67GHz when I launch apps so I'm satisfied that it's at least doing ''something'' for the time being. :^)<br />
<br />
Again, I refer you to the [[Beginners_Guide#Configuring_CPU_frequency_scaling|Beginners Guide]] as a starting point. I have an Intel based machine so I also relied heavily on the [[SpeedStep|SpeedStep]] guide. I got the cpudyn method to work best so that's what I've stuck with so far. Nothing really exciting here, I followed the guides mentioned and then added the appropriate daemons in the DAEMONS array in /etc/rc.conf.<br />
<br />
I also ended up with acpi_cpufreq, cpufreq_userspace and cpufreq_ondemand modules in my MODULES array in /etc/rc.conf after my failed attempts to get frequency scaling to work. I'm not sure if that's necessary or if it's even advisable but it hasn't broken my system yet so I've just left them alone.<br />
<br />
===Sound and Headphones===<br />
The issue with the sound wasn't the sound itself (well, actually it was, the internal speaker sucks :^) ) but the (apparently?) widespread problem of said speakers not being muted when headphones are plugged in. My Googling brought me seemingly endless solutions to this problem which didn't work .. these were some of my favorites:<br />
<br />
* Consider it a feature!<br />
* Just cut the wires to the internal speaker.<br />
* Don't do anything that needs sound.<br />
<br />
Well I really don't want to annoy everyone within earshot, void my warranty or sit in silence while hacking out programs at the last minute so the following are a largely hodge-podge conglomeration of "solutions" I found. I'm not sure if any one of these did it or the combination of them all, but, again, it works so I'm not going to touch it!<br />
<br />
* Grab alsa plugins (which I already I had IIRC)<br />
pacman -S alsa-plugin<br />
<br />
* Grab jack-audio-connection-kit (kind of makes sense from the name I guess?)<br />
pacman -S jack-audio-connection-kit<br />
<br />
* Then on some of the forums for other distros I saw a lot of suggestions to edit /etc/modprobe.conf in some form or fashion. Here's what mine looks like now and everything seems to work so I've just left it.<br />
options snd-hda-intel model=auto<br />
<br />
==Alternate Solution?==<br />
* I managed to get the headphones muting properly by adding this line to /etc/modprobe.conf<br />
options snd-hda-intel model=laptop<br />
<br />
==To Do==<br />
There are still a few things I'd like to get working at some point so if anyone is reading this and has any suggestions I'd love to hear them. :-) Most are pretty low priority/eye candy type stuff.<br />
<br />
*I'd like to have something like MacBooks where they "gradually" dim when idle as opposed to "entirely on" and "entirely off". I think that would come in handy when I just have my notebook open as a reference or something where I could still read it but not need it sitting there sucking my battery dry at full illumination. <br />
** xbacklight -set 30 -time 60000 <--dim over a minute<br />
*Anything to extend battery life. I haven't really looked into it but I'd like to find a way to scale the core voltage as well as frequency. I've seen Intel utilities that can do that on Windows desktops but nothing so far for Linux<br />
*A way to kill the wireless card in software. This notebook comes with a button right by the power button to kill the wireless. It's not a big deal to hit the button I guess but it would be pretty neat if there was a way to simulate hitting the button in case I forget or I lose wireless connection for extended periods. I'm not even sure if this is possible or how it could be done, though.</div>Bavardagehttps://wiki.archlinux.org/index.php?title=Hotkeys&diff=37190Hotkeys2008-02-15T19:30:41Z<p>Bavardage: changed typo: xbinkdekysrc to xbindkeysrc</p>
<hr />
<div>[[Category:Input devices (English)]]<br />
=Introduction=<br />
Many keyboards (mainly on laptops) include some "special keys", which are supposed to execute an app or to print special characters (not included in the standard national keymaps). The great variety of layouts of these keyboards determines some initial problems when you install linux in your system, since the keys do not work out of the box; however, once again, linux gives you the freedom to configure these keys to do exactly what you want. Only a minority of these keys are not seen at all by the linux kernel and thus cannot be used.<br />
<br />
There are many options to deal with special keys in linux (we are going to call them 'hotkeys' in what follows). The solutions discussed in this howto allow you to use them independently from the window manager or desktop environment you chose; moreover you will be able to use them in three possible ways (the second and the third way can not coexist for the same key):<br />
#to print a character in console;<br />
#to print a character in X;<br />
#to execute an app in X.<br />
Actually, you can do also the fourth thing, i.e. to execute an app in console, but this is made with a silly work-around and will be briefly described when discussing the first use in the list above (see [[#Printing characters in the console|below]]).<br />
<br />
Other approaches use comprehensive applications aiming to solve these problems (see e.g. the wiki howtos for [[Extra Keyboard Keys|keytouch]] and for [[Lineak]]), but these solutions are generally built on a wide database of known models of keyboards: this database seems to be condemned to be incomplete, since the variety of keyboard models does never stop to grow. The approach here considered allows the user to work with the internals of the system, tailoring the configuration to his own system as it is. Moreover, the other solutions assume that you want to use the hotkeys only when you are in X, while it is possible to take profit of them also if you are a console lover.<br />
<br />
All the keys we can hope to use in linux has a scancode. This scancode is generally associated with a keycode. This keycode is generally associated with a character to print in the console keymap. This keycode is also translated by X in another code, which the X keymaps generally bind to a certain character or to a certain command to run. Well, when an hotkey does not work for us, one or more of these things that generally happen do not happen. <br />
First of all, we have to discover what is the problem. <br />
This diagnosis will be explained in the [[#The diagnosis|first section]], but we sum up the possible scenarios, so that after the diagnosis we know where to look for a suitable medicine. We have to verify if the key has a scancode. If it has not a scancode, there is no hope that it works, so we have to give up. If it has a scancode but no keycode, we have to associate the scancode with a keycode: this will be explained in the [[#Associate scancodes with keycodes|second section]]. If it has already a keycode or if you gave it a keycode thanks to the second section, then we have to bind it to one or more of the three possible uses listed above: the [[#Printing characters in the console|third section]] explains how to make the key print a character in console; the [[#Printing characters in X|fourth section]] explains how to make the key print a character in X using xmodmap; the [[#Running applications in X|fifth section]] explains how to make the key run an application when in X, using xbindkeys.<br />
<br />
= The diagnosis =<br />
The most global way to diagnose the situation is to go in console and use the 'showkey' utility. Please note that this utility will not work when in X so you'll need to switch to another tty (e.g. CTRL+ALT+F6).<br />
<br />
First of all we run:<br />
$ showkey <br />
without options: 'showkey' waits for ten seconds that we press a key (after ten seconds it quits automatically) and displays the keycode of the key we pressed. Two scenarios are possible:<br />
#nothing is displayed: in this case the key has not a keycode and you have to read further this section;<br />
#some mysterious hexadecimal numbers are displayed; in this case the kernel already assigns a keycode to the key; we can pass over to sections [[#Printing characters in the console|3]], [[#Printing characters in X|4]] or [[#Running applications in X|5]], according to what we want to do with that key.<br />
In the first scenario, we have to investigate if the key has at least a scancode. The 'showkey' utility can help us again. Just use the '-s' option:<br />
$ showkey -s<br />
When we press our hotkey, two scenarios are possible:<br />
#nothing is displayed: the key is not seen in any way by our os, we whould give up;<br />
#a decimal code is displayed; the hotkey has a scancode; the [[#Associate_scancodes_with_keycodes|next section]] will help you to associate this scancode with a keycode.<br />
<br />
= Associate scancodes with keycodes =<br />
In order to accomplish this task, we need to resort to the utility 'setkeycodes', which, as you can see in its man page, associates scancodes to keycodes. Obviously enough, it takes two arguments: the first argument is the scancode, the second argument is the keycode. However, it is not always easy to determine these arguments. In order to determine the scancode, the output of the 'showkey -s' we used in the section above is not always illuminating, since sometimes the hotkeys - and the normal keys too - generate a double scancode. The simplest way to determine the exact scancode is to look at the system log: in fact, any time we press a key which has a scancode but no keycode, the kernel suggests us to use just 'setkeycodes' to assign a keycode to it. In the message the kernel gives us also the scancode we have to use actually. We will find it in the system log. However, also this code is not always usable as it is: when it is composed of four characters and starts with an 'e', then we can use it as it is as the first argument for 'setkeycodes'. On the contrary, when the kernel gives us only two digits, we have to prepend '0x' to it. As an example, suppose that the kernel tells us that the scancode is 71; then the first argument for 'setkeycodes' will be 0x71.<br />
<br />
The second argument is partially arbitrary. Partially! In fact:<br />
#the keycode has to be in the range 1-127;<br />
#it should not conflict with the keycodes already mapped to a character in your keymap.<br />
In order to respect the second condition, you have to look at your keymap. In configuring your system through /etc/rc.conf, you have chosen your keymap, or decided to stay with the default one: in fact rc.conf includes a 'KEYMAP' setting. The keymaps are stored in your system in one of the subfolders into /usr/share/kbd/keymaps/i386/. E.g., mine is the Italian keymap and its path is /usr/share/kbd/keymaps/i386/qwerty/it.map.gz. It is a text file compressed with gzip2. Let us gunzip it.<br />
# gunzip /usr/share/kbd/keymaps/i386/qwerty/it.map.gz<br />
Now we can read it (sometimes less is able to read also gzipped files: in this case the above passage is dispensable):<br />
# less /usr/share/kbd/keymaps/i386/qwerty/it.map<br />
We have to choose a keycode not conflicting with those already associated with characters. Most of the lines in the keymap are of the following format:<br />
keycode <keycode> = <keysym><br />
These lines are ordered according to the numeric value of the keycode, thus it is easy to find the highest keycode used by the keymap. Thus, the second argument for 'setkeycodes" has to in the range between the successor of this highest keycode and 127. <br />
<br />
Let us say that 112 is in this range (this is actually true with the italian keymap): now we can actually use 'setkeycodes':<br />
# setkeycodes 0x71 112<br />
If we run 'showkey' again, we can see that our hotkey has now the keycode 112. However, this is true only for the current session. To make this permanent, we need to execute 'setkeycodes' each time we boot our system. This can be done inserting the following line in /etc/rc.local:<br />
setkeycodes 0x71 112 &<br />
<br />
== Printing characters in the console ==<br />
When we are in console, we can use our hotkeys to print a certain character. Moreover we can also print a sequence of characters and some escape sequences. Thus, if we print the sequence of characters constituting a command and afterwards an escape character for a new line, that command will be executed!<br />
<br />
In order to do this, we could modify our console keymap. However, I suggest not to do this, since that is a delicate file and since it will be rewritten anytime we update the package it belongs to. It is better to integrate the existing keymap with a personal keymap. The utility 'loadkeys' can do this. <br />
<br />
First of all, we need to write down this file. You can put it as you prefer, but I prefer to mimic partially the hierarchy of the default keymaps into /usr/local. So:<br />
# mkdir -p /usr/local/share/kbd/keymaps<br />
# vim /usr/local/share/kbd/keymaps/personal.map<br />
As a side note, it is worth noting that such a personal keymap is useful also to redefine the behavior of keys already treated by the default keymap: in fact, when we load it with 'loadkeys' the directives in the default keymap will be replaced when they conflict with the new directives and conserved otherwise. <br />
<br />
Anyway, we need two kinds of directives in our personal keymaps. First of all, the keycode directives, with the format we have seen above in the default keymaps. These directives associate a keycode with a keysym. Keysyms represent keyboard actions. The actions available include outputting character codes or character sequences, switching consoles or keymaps, booting the machine etc. (The complete list can be obtained with <br />
$ dumpkeys -l<br />
Anyway, most of them are intuitive. If we want our key to output an 'e', the directive will be:<br />
keycode 112 = e<br />
If we want our hotkey to output the symbol of the euro currency, the directive will be:<br />
keycode 112 = euro<br />
Some keysym are not immediately connected to a keyboard actions. In particular the keysyms constituted by a capital F and two digits constituting a number greater than 30 are always free. This is useful for us if we want our hotkey to output a sequence of characters and other actions. In fact we can first of all bind our character to such a keysym:<br />
keycode 112 = F70<br />
Then we use another kind of directive, which binds the keysym to an action. E.g., if we want our hotkey to output a literal "Hello":<br />
string F70 = "Hello"<br />
This can seem not very useful. But we can use it to print and execute commands. In order to execute the printed command, I need to use an escape sequence corresponding to a new line. E.g., I can want an hotkey to hibernate my laptop also when I am a user (through sudo). In this case I write the following directive in my personal keymap.<br />
string F70 = "sudo /usr/sbin/hibernate\n"<br />
In order to take profit of my personal keymap, I have to load it with 'loadkeys':<br />
$ loadkeys /usr/local/share/kbd/keymaps/personal.map<br />
Also in this case, this is valid only for the current session. In order to accomplish the same result each time I boot my machine, I have to insert another line in /etc/rc.local. This line should come after the occurrences of 'setkeycodes' discussed in section 2, since the personal keymap resorts to the keycodes assigned through 'setkeycodes':<br />
loadkeys -q /usr/local/share/kbd/keymaps/personal.map&<br />
The '-q' option simply avoids that a confirmation message is printed to stdin during the boot process.<br />
<br />
== Printing characters in X ==<br />
Fortunately, when a character has a keycode in the system it is also seen inside X. X gives it a keycode: however, it is very important to stress that the X keycode is DIFFERENT from the system keycode. If you had to pass through section 1 of this article to assign a system keycode to your hotkey, you MUST forget this keycode when dealing with X, because X assigns a different keycode to the key (but requires that the key has a system keycode whatsoever). <br />
<br />
The most traditional and proficient way to make a key output a character when you are in X is to use xmodmap. Xmodmap is roughly the X equivalent of 'loadkeys' (see section 3): it reads a file containing some directives. As 'loadkeys', it can be used to modify many aspects of the behaviour of your keyboard (such as modifiers, etc.), but I will not cover these aspects in this article. The only kind of directive I am interested in here associates an X keycode to a keysym. 'xmodmap' is included in the 'xorg-server-utils' package.<br />
# pacman -S xorg-server-utils<br />
In order to use it we need to discover the X keycode of our beloved hotkey: we resort to 'xev'. 'xev' is included in the 'xorg-utils' package.<br />
# pacman -S xorg-utils<br />
'xev' (run it from a terminal window) open a white window and outputs in the terminal some codes and infos when you press (or relase) a key or move your mouse. Its output is redundant and difficult. Anyway, you will see clearly into it when you press your hotkey:<br />
keycode: <theXkeycodeofyourhotkey><br />
Once you have discovered the X keycodes of your hotkeys, you are ready to write the file that 'xmodmap' will parse. You can put it where you like, but since the xserver is executed by a user, it is customary to make it an hidden file in the home directory of the user:<br />
$ vim ~/.Xmodmap<br />
In this file, you have to list the keycode directives, with the following syntax:<br />
keycode <Xkeycode> = <keysym><br />
The list of X keysyms can be read in /usr/include/X11/keysymdef.h. Anyway, most of them are intuitive. Let us say that 'xev' has said that the X keycode of my hotkey is 239. If I want it to output a literal 'e', I will write the following directive:<br />
keycode 239 = e<br />
If I want it to output the symbol of the American currency, I will write the following directive:<br />
keycode 239 = dollar<br />
Finally I have to source the file with xmodmap:<br />
$ xmodmap ~/.Xmodmap<br />
Obviously, this will work only for the current X session, but it is better to make this automatically anytime I start X. This should be done in different ways according to your system configuration. E.g., if you use the old plain 'startx', you have to put the following line in .xinitrc before the line when you launch your window manager:<br />
xmodmap ~/.Xmodmap &<br />
<br />
<b>NOTE:</b><br />
This can also be used to assign functions to multimedia keys. Special functions can be found in /usr/share/X11/XKeysymDB.<br />
<br />
My (tkjacobsen) ~/.Xmodmap:<br />
<pre><br />
keycode 160 = XF86AudioMute<br />
keycode 176 = XF86AudioRaiseVolume<br />
keycode 174 = XF86AudioLowerVolume<br />
</pre><br />
<br />
Multimedia programs such as Rhythmbox and Exaile are designed to work with keys assigned to XF86 Symbols out-of-the-box, without the need to configure a third-party application.<br />
<br />
== Running applications in X ==<br />
There are several utilities which aim to help you to bind keys (or keys combinations) to certain apps. Basically, they follow two main philosophies: some of them include a database of existing keyboards and, once you have defined the model of your keyboard, should associate to keys the 'right' action (i.e. corresponding to the icon on the key...); some others allow you to associate the action you like to whatever key or key combination, disregarding stuff like icons. I have a strong preference for this second philosophy and will propose to use one of the utilities of this second kind. [[Lineak]] is an example of the first approach.<br />
<br />
Another option is to use the configuration files of the window manager. This is a very good solution, although it often requires that the key is associated (through xmodmap) with a keysym which the window manager then associates to an app to run. However, it is different for each of the existing window managers and can not be covered in this article.<br />
<br />
I propose to use xbindkeys. xbindkeys can be used together with any window manager (but its shortcuts can conflict with the shortcuts defined by the window manager).<br />
# pacman -S xbindkeys<br />
xbindkeys is widely documented in its man page:<br />
$ man xbindkeys <br />
Xbindkeys includes an utility to detect the X keycodes of keys and key combinations without resorting to 'xev'. Its output is much more readable than 'xev' output.<br />
$ xbindkeys -mk<br />
In the configuration file you can associate commands both to X keycodes and to keysyms. Your hotkeys, if you haven't already configured them through 'xmodmap' (see Section 4 above) are actually identifiable only through an X keycode. The man page explains the syntax of the configuration file (~/.xbindkeysrc) in great detail. The following is just one example of what can be done with Volume/Mute keys:<br />
<pre><br />
# vol mute<br />
"amixer set Master mute"<br />
m:0x10 + c:160<br />
# vol up<br />
"amixer set Master 2dB+ unmute"<br />
m:0x10 + c:176<br />
# vol dn<br />
"amixer set Master 2dB- unmute"<br />
m:0x10 + c:174<br />
</pre><br />
<br />
Once configured, 'xbindkeys' should be run when an X syntax starts. Thus, provided that you use 'startx' to start your x session, you can add the following line to your .xinitrc:<br />
xbindkeys &<br />
<br />
In this way, xbindkeys will fork in the background and be ready to react when you press the hotkeys (or the normal keys, or key combinations) you defined in the config file.</div>Bavardagehttps://wiki.archlinux.org/index.php?title=HP_530&diff=37189HP 5302008-02-15T19:15:53Z<p>Bavardage: </p>
<hr />
<div>[[Category:Laptops (English)]]<br />
[[Category:HOWTOs (English)]]<br />
{{stub}}<br />
<br />
==Introduction==<br />
I was looking for a cheap, good bang for the buck laptop I could take back and forth to class and also something I could play with Linux on outside of desktop/workstation boxes. I browsed NewEgg for a few weeks looking for good deals and finally settled on this one. There were two versions, one was a Celeron with 512MB RAM and about the time I settled on it, the price of this one dropped so I went ahead and spent the extra for a Core Duo, double the RAM and a DVD burner.<br />
<br />
==Specs==<br />
It's a pretty run of the mill low end laptop. Nothing too fancy or too expensive .. here are the highlights.<br />
<br />
*Model 530 (GU337AT#ABA)<br />
*Screen 15.4" WXGA<br />
*Memory Size 1GB DDR2<br />
*Hard Disk 80GB<br />
*Optical Drive DVD±R/RW<br />
*Graphics Card Intel GMA950<br />
*Video Memory shared memory<br />
*CPU Type Intel Core Duo<br />
*CPU Speed T2300E(1.66GHz)<br />
*CPU FSB 667MHz<br />
*CPU L2 Cache 2MB<br />
*Resolution 1280 x 800<br />
*GPU/VPU Intel GMA950<br />
*Video Memory Up to 224-MB shared system memory<br />
*Graphic Type Integrated Card<br />
*HD Interface SATA<br />
*Memory Slots 2 x SO-DIMM<br />
*Memory Speed DDR2 667<br />
<br />
==Installation==<br />
The base install was extremely easy. Coming from Slackware I had a pretty good grasp of a text-based installer so I was right at home during the initial configuration. However, since this was my first experience with Arch I was a bit lost when it came time to configure the system. :^) I browsed the wiki here for a bit until I stumbled on the great [[Beginners_Guide|Beginners Guide]] which I used to update the system, grab Xorg, XFCE and pretty much everything else it mentioned. If you're an Arch newb like I am I strongly suggest browsing over there and checking out that Intro, I can't recommend it enough. :-)<br />
===Initial===<br />
Combine the fact I was coming to Arch from Slack with my OCD nature, I ended up with a the following partitioning scheme. <br />
<br />
/dev/sda6 /boot<br />
/dev/sda7 /<br />
/dev/sda8 /usr<br />
/dev/sda9 /home<br />
/dev/sda10 /var<br />
/dev/sda11 /tmp<br />
<br />
With a 2048MB SWAP space (2*1024RAM)<br />
<br />
===Post Install Config===<br />
I pretty much went down the aforementioned [[Beginners_Guide|Beginners Guide]] following the first reboot, so I won't go into a great deal of detail. Besides everyone has their own preferences on a lot of that stuff like media players and themes, fonts etc. <br />
<br />
I updated via pacman then grabbed the Xorg, sound (alsa), XFCE and fonts packages mentioned there. Then I configured DBUS and HAL which were pretty much working out of the box and edited /etc/rc.conf to load the DAEMONS and MODULES I needed. Everything worked on the first try with little or no tweaking needed so I was up and running my first fully functional Arch install. :-)<br />
<br />
==Issues==<br />
I only had three real issues during the install -- wireless, CPU frequency scaling and the (prevalent?) Linux + Laptop problem of the internal speaker not being muted when headphones are plugged in. I'll tackle them in order of severity.<br />
===Wireless===<br />
A laptop without wireless is pretty useless, and this is one of the areas Linux hasn't really shined in the past so I was a bit apprehensive when my wireless didn't work right out of the box. However after reading through most of the documentation on the Wiki and the Forums I got it working, so there is hope if you're struggling with it too.<br />
<br />
If you haven't already, take a look at the [[Wireless_Setup|wireless setup]] page. It's a good starting point/intro for wireless newbs like me. On there it mentions the method I use here as being the "non-preferred" method, but I couldn't get the "preferred" method there to work. Now that I know a little bit more about the process I may try to go back and look into it, but as long as it's not broken, I'm reluctant to "fix" it. :-/<br />
<br />
=====Hardware/Kernel Stuff=====<br />
First I grabbed the wireless tools package.<br />
pacman -S wireless_tools<br />
<br />
Then I figured out which type of card I had with lshwd (I actually had to grab lshwd with pacman first, but no biggie there!)<br />
lshwd<br />
.<br />
.<br />
10:00.0 Class 0280: Intel Corporation|PRO/Wireless 3945ABG (ipw3945)<br />
.<br />
.<br />
<br />
So, I need the ipw3945 module which was already on my system, as determined by:<br />
modinfo ipw3945<br />
<br />
I checked to see if it was loaded already<br />
lsmod | grep 3945<br />
<br />
It wasn't, but the iwl3945 ''was'' so I removed it. (At this point I had installed so many different modules and packages trying to get wireless to work I'm not sure exactly what comes pre-loaded with the default install so YMMV on this next little bit).<br />
rmmod iwl3945<br />
<br />
Then I dropped in the ipw3945 module<br />
modprobe ipw3945<br />
<br />
Finally I needed to insert the ipw3945 module (and remove any iwl3945) into the MODULES array in /etc/rc.conf and ipw3945d daemon into the DAEMONS array in the same file. I'm not sure if it matters, but I made sure I put the daemon before all the other networking related daemons, again, YMMV slightly.<br />
<br />
At this point you should have everything ready to go on the hardware side. You man want to reboot to make sure you got all the stuff in /etc/rc.conf correct since I thought I had things working a couple times until I rebooted then everything magically broke again. :^)<br />
<br />
=====Software/User Space Stuff=====<br />
(NOTE: I'm not endorsing one program/utility over another here, I'm just sharing what I got to work. :-) )<br />
I browsed around the Arch site here and Google looking for a nice wireless connection utility and tried a couple different things. I tried [[Networkmanager|networkmanager]] but that didn't really get me anywhere. Then I tried [[Wicd|wicd]] and it had all the features I needed and seemed to work alright so I went with it. I pretty much followed the procedure on the [[Wicd|wicd]] page and I was up and running in no time. I added wicd to my DAEMON array in /etc/rc.conf and launched it via the tray icon and it found my wireless connection ... and six of my neighbors connections too. :^)<br />
<br />
=====Summary=====<br />
Basically I had no idea how to do wireless on any platform when I started. This section isn't really intended to be a guide on how you ''SHOULD'' do things, rather an electronic form of my notes on how I ''DID'' do things. :-)<br />
<br />
===CPU Frequency Scaling===<br />
DISCLAIMER: I'm still not entirely sure I've got this working like it should but I can watch the little Applet I put on my Panel change from 1GHz to 1.67GHz when I launch apps so I'm satisfied that it's at least doing ''something'' for the time being. :^)<br />
<br />
Again, I refer you to the [[Beginners_Guide#Configuring_CPU_frequency_scaling|Beginners Guide]] as a starting point. I have an Intel based machine so I also relied heavily on the [[SpeedStep|SpeedStep]] guide. I got the cpudyn method to work best so that's what I've stuck with so far. Nothing really exciting here, I followed the guides mentioned and then added the appropriate daemons in the DAEMONS array in /etc/rc.conf.<br />
<br />
I also ended up with acpi_cpufreq, cpufreq_userspace and cpufreq_ondemand modules in my MODULES array in /etc/rc.conf after my failed attempts to get frequency scaling to work. I'm not sure if that's necessary or if it's even advisable but it hasn't broken my system yet so I've just left them alone.<br />
<br />
===Sound and Headphones===<br />
The issue with the sound wasn't the sound itself (well, actually it was, the internal speaker sucks :^) ) but the (apparently?) widespread problem of said speakers not being muted when headphones are plugged in. My Googling brought me seemingly endless solutions to this problem which didn't work .. these were some of my favorites:<br />
<br />
* Consider it a feature!<br />
* Just cut the wires to the internal speaker.<br />
* Don't do anything that needs sound.<br />
<br />
Well I really don't want to annoy everyone within earshot, void my warranty or sit in silence while hacking out programs at the last minute so the following are a largely hodge-podge conglomeration of "solutions" I found. I'm not sure if any one of these did it or the combination of them all, but, again, it works so I'm not going to touch it!<br />
<br />
* Grab alsa plugins (which I already I had IIRC)<br />
pacman -S alsa-plugin<br />
<br />
* Grab jack-audio-connection-kit (kind of makes sense from the name I guess?)<br />
pacman -S jack-audio-connection-kit<br />
<br />
* Then on some of the forums for other distros I saw a lot of suggestions to edit /etc/modprobe.conf in some form or fashion. Here's what mine looks like now and everything seems to work so I've just left it.<br />
options snd-hda-intel model=auto<br />
<br />
==Alternate Solution?==<br />
* I managed to get the headphones muting properly by adding this line to /etc/modprobe.conf<br />
options snd-hda-intel model=laptop<br />
<br />
==To Do==<br />
There are still a few things I'd like to get working at some point so if anyone is reading this and has any suggestions I'd love to hear them. :-) Most are pretty low priority/eye candy type stuff.<br />
<br />
*I'd like to have something like MacBooks where they "gradually" dim when idle as opposed to "entirely on" and "entirely off". I think that would come in handy when I just have my notebook open as a reference or something where I could still read it but not need it sitting there sucking my battery dry at full illumination. <br />
*Anything to extend battery life. I haven't really looked into it but I'd like to find a way to scale the core voltage as well as frequency. I've seen Intel utilities that can do that on Windows desktops but nothing so far for Linux<br />
*A way to kill the wireless card in software. This notebook comes with a button right by the power button to kill the wireless. It's not a big deal to hit the button I guess but it would be pretty neat if there was a way to simulate hitting the button in case I forget or I lose wireless connection for extended periods. I'm not even sure if this is possible or how it could be done, though.</div>Bavardage