Instead of having to use one of the various javascript rss libraries, one can take advantage of google reader’s (undocumented) api.
note: the following assumes that the jQuery library is being used
Read the rest of this entry »
Instead of having to use one of the various javascript rss libraries, one can take advantage of google reader’s (undocumented) api.
note: the following assumes that the jQuery library is being used
Read the rest of this entry »
Just a little hack using show to make the earlier summing series example look a bit nicer.
Start with what I had before:
sumseries a b f = sum[f n|n<-[a..b]]
I have swapped around and renamed the arguments a little, just to tidy it up a tad.
Summing the first 5 evens (2 + 4 + 6 + 8 + 10):
*Main> sumseries 1 5 (\r -> 2*r)
30
So, I want to prettify it. I want to use Σ for the sum function. So this is easy, right? Just call the function Σ and be done with it. Not so – Sigma is an uppercase letter, and in haskell, these are reserved for datatypes.
Solution: make a datatype
data Σ a = Σ a a (a -> a)
Sure, we have a datatype, but we can’t call this. Now for the hack:
instance (Show a, Num a, Enum a) => Show (Σ a) where
show (Σ a b f) = show $ sumseries a b f
– when we want to show the datatype, like in ghci’s prompt, we call sumseries and show the result of that instead.
Example:
*Main> Σ 1 5 (\r -> 2*r)
30
or more concisely
*Main> Σ 1 5 (*2)
30
If you’ve studied capacitors, you’ll have (very probably) come across the decay equation:
where
is resistance,
is capacitance,
is the charge on the capacitor at time
and
is the initial charge.
Firstly from the basics of circuits, we know that (yes, I’m using the british convention with regards the symbol for voltage, I understand elsewhere
is used instead).
Now when we discharge a capacitor through a circuit, the e.m.f.s are supplied by the capacitor.
Now substitutiting for V in the above equation gives
So we now have an equation for the current in the circuit, but wait, where does this current come from? It’s the capacitor discharging – this current is equal to the rate of discharge of the capacitor, so:
So substituting the above expression for I
Ooh look, a differential equation.
Seperate the variables giving:
where k is some constant.
If we define the initial charge to be – the charge when t = 0
so we now can replace giving:
MY WORK HERE IS DONE
:D
I came across PyWebKitGtk and had to try it.
A browser, in 14 lines.
#!/usr/bin/env python
import gtk
import webkit
import gobject
gobject.threads_init()
win = gtk.Window()
bro = webkit.WebView()
bro.open("http://www.google.com")
win.add(bro)
win.show_all()
gtk.main()
And the obligatory screenshot:
I changed my wordpress theme to something dark so want a new header – why not a blackboard :D
This morning Dream_Team brought up the age-old debate of whether
which of course it does.
Although this seems fairly conclusive, there is a much nicer (IMO) way.
One can treat the infintite decimal expansion as a geometric series.
Then it becomes apparent that the value of is equal to the sum to infinity of the geometric series.
And for a geometric series with common difference and first term
for explanation see below
So for
Voilà.
This then prompted me to code some haskell, creating types for geometric and arithmetic series, but that post can come later.
Now for the sum to infinity:
This almost makes me want to learn APL. Almost.
Just a python script, to print the name of the current desktop. Could be useful to pipe to conky or something.
#!/usr/bin/env python
from Xlib import display, Xatom
dsp = display.Display()
rootwin = dsp.screen().root
DESKTOP_NAMES = dsp.intern_atom("_NET_DESKTOP_NAMES")
CURRENT_DESKTOP = dsp.intern_atom("_NET_CURRENT_DESKTOP")
def get_names():
names = rootwin.get_full_property(DESKTOP_NAMES, 0)
names = names.value.split("\x00")
return names
def current_desktop():
return rootwin.get_full_property(CURRENT_DESKTOP,
Xatom.CARDINAL
).value[0]
try:
print get_names()[current_desktop()]
except:
print "error getting name"
Requires the python bindings for xlib
Set the _NET_WM_WINDOW_OPACITY property to an integer between 0x0 and 0xffffffff
An example function to set the opacity of a window using Xlib and python:
from Xlib import Xatom
def setOpacity(self, display, window, opacity):
if 0.0 < = opacity <= 1.0:
real_opacity = int(opacity * 0xffffffff)
window.change_property(
display.get_atom('_NET_WM_WINDOW_OPACITY'),
Xatom.CARDINAL,
32,
[real_opacity,],
)
else:
return
For this to work however, a composite manager of some kind must be running, but xcompmgr will suffice.