Skip to content

Instantly share code, notes, and snippets.

@ps
ps / Users.scala
Created May 15, 2017 01:48
Some(Int) vs just Int
// implementation 1
object Users {
var users: Seq[User] = Seq()
def delete(id: Long) : Option[Int] = {
val originalSize = users.length
this.users = users.filterNot(_.id == id)
Some(originalSize - users.length)
}
}
@ps
ps / bug.c
Last active November 30, 2016 16:14
Fun with locks and condition variables
typedef struct WorkerParams {
int thread_id;
Log * log;
Jobs * jobs;
pthread_mutex_t jobs_lock;
pthread_cond_t work_added;
} WorkerParams;
void main() {
launch_master_node(3);
# deb cdrom:[Ubuntu-Server 14.10 _Utopic Unicorn_ - Rlease amd64 / utopic main restricted
#deb cdrom:[Ubuntu-Server 14.10 _Utopic Unicorn_ - Release amd64 / utopic main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://mirrors.digitalocean.com/ubuntu-old/ utopic main restricted
deb-src http://mirrors.digitalocean.com/ubuntu-old/ utopic main restricted
## Major bug fix updates produced after the final release of the
@ps
ps / gist:7865aae997738344e63927f97402c90e
Last active April 18, 2016 12:45
do droplet errors
Ign http://downloads-distro.mongodb.org dist InRelease
Hit http://downloads-distro.mongodb.org dist Release.gpg
Hit http://downloads-distro.mongodb.org dist Release
Hit http://downloads-distro.mongodb.org dist/10gen amd64 Packages
Ign http://old-releases.ubuntu.com utopic-security InRelease
Hit http://downloads-distro.mongodb.org dist/10gen i386 Packages
Hit http://old-releases.ubuntu.com utopic-security Release.gpg
Ign http://downloads-distro.mongodb.org dist/10gen Translation-en_US
Ign http://downloads-distro.mongodb.
@ps
ps / gist:e03fa57249e00ba938136cf765bd04b8
Created April 11, 2016 03:02
add another site to laravel homestead
edit Homestead.yaml and add under sites section
-map: domain.app
to: /path/to/public
on own machine (NOT VM) edit /etc/hosts and add another entry, grab IP from Homestead.yaml and add line:
<ip-from-yaml> domain.app
vagrant reload --provision
DONE!
@ps
ps / extract.py
Last active February 20, 2016 00:53
Get x,y coordinates in order of left to right occurance
# Place: "fprintf('[%i, %i],',round((maxr+minr)/2), round((maxc + minc)/2));" in Matlab for image test1.bmp or test2.bmp
# put the output into test1/test2 var as below
# script prints out centers of figures on image in order (left to right then top to bottom)
def gen_data(a,mod):
a_by_rows = []
temp_row = []
i=1
for x,y in a:
temp_row.append([y,x])
@ps
ps / gist:5810548230ee2e5583c6
Created April 28, 2015 03:11
using objdump
objdump -d -M intel -S test.o
@ps
ps / gist:97cc54e97e137c43b882
Created April 20, 2015 19:18
Counting the total number of occurrences of a string recursively
grep -c -r 'import' Python-2.5.4/ | \
awk -F : '{total += $2; print $1, $2} END { print "Total:", total }'
Source: http://stackoverflow.com/questions/884591/grep-recursive-and-count
@ps
ps / gist:6ac0b69609661e3d8d6f
Created January 18, 2015 17:47
Vim Skeleton Java Code
If you get tired of typing public class... and then the main method in vim
then here is your solution.
autocmd BufNewFile *.java
\ exe "normal Opublic class " . expand('%:t:r') . " {\npublic static void main(String [] args) {\n\n}\n}\<Esc>1G"
Just insert it into your '.vimrc' and that's it! The next time you open a brand new Java file you
will see a template.
@ps
ps / gist:25f50a34c04e95c0a278
Last active September 3, 2015 21:56
Authenticating Mongo
1. mongo
2. use <your-database-name-here>
3. db.addUser('pawel','test')
4. exit
5. vim /etc/mongodb.conf uncomment the line '#auth=true'
6. sudo service mongodb stop
7. sudo service mongodb start
7.5 Run your application as it is now and verify that it fails since it is missing authentication.
8. in your python code add: db.authenticate('pawel','test')
9. sudo service apache2 restart