Skip to content

Instantly share code, notes, and snippets.

@nagisa
nagisa / gist:1152069
Created August 17, 2011 17:22
Split by sentence
#settings
DESCRIPTION_LEN = 5
DESCRIPTION_SPLITTER = r'(?<=[.?!。!?])\s+'
#Modelis
def get_description(self, splitter = re.compile(settings.DESCRIPTION_SPLITTER)):
if self.short_content:
return self.short_content
else:
return ' '.join(splitter.split(self.content, settings.DESCRIPTION_LEN)[:-1])
@nagisa
nagisa / gist:1170125
Created August 25, 2011 06:59
Benchmarking JavaScript
start = new Date();
for(i=0; i<1000000; i++){String(Math.floor(Math.random()*1000000))};
console.log(new Date()-start)
>> 2054
start = new Date();
for(i=0; i<1000000; i++){String(~~(Math.random()*1000000))};
console.log(new Date()-start)
>> 1752
@nagisa
nagisa / cookie.py
Created August 28, 2011 14:18
Cookie
body{background:#ffffff;color:#111111;}
h1,h2,h3,h4,h5,h6{color:#222222;}
.content{box-shadow:0 0 5px #111111;-moz-box-shadow:0 0 5px #111111;-webkit-box-shadow:0 0 5px #111111;border:#000 solid;border-width:0 1px;}
#logo{background:url("http://kazlauskas.me/m/image/logo.svg") 100%;height:100px;}
>> stash.set('a', function(){return true;})
<< 1
>> stash.add('a', 'adding string') //It shouldn't replace old value.
<< 1
>> stash.get('a') //Unexpected value, we would expect old function.
<< "adding string"
//For people who may want replace action, they could use stash.cut(); and stash.set(); again.
*.pyc
*.log
*.sql
*.sqlite
.DS_Store?
ehthumbs.db
Icon?
Thumbs.db
.gitignore
Sep 6 16:39:05 localhost pulseaudio[1221]: alsa-sink.c: ALSA woke us up to write new data to the device, but there was actually nothing to write!
Sep 6 16:39:05 localhost pulseaudio[1221]: alsa-sink.c: Most likely this is a bug in the ALSA driver 'snd_hda_intel'. Please report this issue to the ALSA developers.
Sep 6 16:39:05 localhost pulseaudio[1221]: alsa-sink.c: We were woken up with POLLOUT set -- however a subsequent snd_pcm_avail() returned 0 or another value < min_avail.
Sep 6 22:24:52 localhost pulseaudio[1221]: alsa-util.c: snd_pcm_avail() returned a value that is exceptionally large: 1176124 bytes (6667 ms).
Sep 6 22:24:52 localhost pulseaudio[1221]: alsa-util.c: Most likely this is a bug in the ALSA driver 'snd_hda_intel'. Please report this issue to the ALSA developers.
@nagisa
nagisa / c_shit.c
Created October 8, 2011 21:29
Running C_SHIT...
#include <stdio.h>
#include <Python.h>
static PyObject * shit(PyObject *self, PyObject *args)
{
signed long long int number;
signed long long int steps;
signed long long int i;
signed long long int the_biggest = 0;
for(i = 0; i < 1000000;i++) {
header .search>form>input[type=submit]::-moz-focus-inner {
padding: 1px!important;
}
#!/bin/bash
. /etc/rc.conf
. /etc/rc.d/functions
# get the number of CPUs
num_cpus=`grep -c processor /proc/cpuinfo`
# set decremented number of CPUs
decr_num_cpus=`expr $num_cpus - 1`