Skip to content

Instantly share code, notes, and snippets.

@ffbit
ffbit / gist:3324358
Created August 11, 2012 13:12
Installing PostgreSQL on Debian linux
$ sudo apt-get install postgresql-9.1 postgresql-client-9.1 postgresql-contrib-9.1 pgadmin3 -t squeeze-backports
$ nmap localhost
$ sudo -u postgres psql
# CREATE ROLE your_uid WITH SUPERUSER LOGIN PASSWORD 'pass';
# CREATE DATABASE your_uid;
# \q
$ psql -U your_uid -W
@ffbit
ffbit / User.java
Created August 13, 2012 20:32
A little JPA 2.0 example that implements naive Twitter User relationships.
package com.ffbit.twitter;
import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Access;
import javax.persistence.AccessType;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
@ffbit
ffbit / hosts
Created August 20, 2012 18:24
Hosts
127.0.0.1 googleads.g.doubleclick.net
127.0.0.1 marketgid.com lady.marketgid.com
127.0.0.1 b.ddestiny.ru
127.0.0.1 imgn.dt00.net mg.dt00.net
127.0.0.1 begun.ru
127.0.0.1 colo1.adriver.ru adriver.ru un1.adriver.ru ad.adriver.ru content.adriver.ru
127.0.0.1 tns-counter.ru
127.0.0.1 banners.gamexp.ru
127.0.0.1 counter.spylog.com spylog.com
127.0.0.1 images.gamenet.ru gamenet.ru go.gamenet.ru
@ffbit
ffbit / gist:3427773
Last active October 9, 2015 02:57
Eclipse Preferences -> Java -> Editor -> Code Assist -> Favorites
org.hamcrest.CoreMatchers
org.junit.Assert
org.junit.matchers.JUnitMatchers
org.mockito.Mockito
@ffbit
ffbit / before (JUnit 4)
Last active October 9, 2015 02:58
Eclipse Preferences -> Java -> Editor -> Templates
@Before
public void ${setUp}() throws Exception {
${import:import('org.junit.Before')}${cursor}
}
@Test
public void itShould${DoSomething}() throws Exception {
${import:import('org.junit.Test')}${cursor}
}
@ffbit
ffbit / time.py
Created August 22, 2012 21:54
Calculating time for the Algorithm course
import math
time = (3.3E-4, 5.0E-9, 6.25E-9)
data = (1, 2, 4, 8, 16, 32, 64)
for t in time:
print("== %s ==" % t)
for d in data:
result = math.pow(d * 1000, 2) * t
print("%s %f" % (d, result))
@ffbit
ffbit / 100-dwarfs-and-candles.py
Created September 2, 2012 11:38
100 dwarfs and candles
n = 100
candles = [False] * n
offset = 1
for dwarf in xrange(n):
dwarf_num = dwarf + offset
for candle in xrange(n):
candle_num = candle + offset
if not candle_num % dwarf_num:
candles[candle] = not candles[candle]
@ffbit
ffbit / create-project
Created September 2, 2012 17:09
Java SE 6.0 Maven scaffolding
#!/bin/bash
SCRIPT_DIR=`dirname $0`
if [ -z $1 ]
then
echo "ERROR: Provide an artifact id"
exit -1
fi
@ffbit
ffbit / gist:3881193
Created October 12, 2012 20:01
Mapping SSD on linux
ls -l /dev/disk/by-uuid
sudo nano /etc/fstab
UUID=aaaaaaaa-aaaa-aaaa-aaaa-c5d849f7592c /ssd ext4 noatime,nodiratime,discard,errors=remount-ro 0 1
sudo mount -a
@ffbit
ffbit / dump.sh
Created October 15, 2012 14:26
PostgreSQL dump
#!/bin/bash
DB="dbname"
HOST="127.0.0.1"
UNAME="uname"
pg_dump --host=$HOST --port=5432 --username=$UNAME $DB | gzip -c > $DB.backup.gz