Some nice #bash commands


#!/bin/bashMake all files lower case in the folder in linuxfor f in `find`; do mv -v "$f" "`echo $f | tr '[A-Z]' '[a-z]'`"; doneRename all files in the directory sequentiallya=1for i in *.mp4; do new=$(printf "%04d.mp4" "$a") #04 pad to length of 4 mv -- "$i" "$new" let a=a+1doneCheck if variable null (not set) or not if [ -z "$var" ] then echo "\$var is empty" fiFunction definitionmain (){ echo "This is a function" # Use the passed parameter in the function. echo "Passed parameter is $1"}main "first parameter"if-else conditionalsif [[ "$1" = "1" ]]; then echo "This is if"elif [[ "$1" = "2" ]]; then echo "This is elif"else echo "This is else"fiFormat current date and time in a nicelyecho "Recent logs are at logs_`date +%Y%m%d_%H%M%S`"Pipe both stderr and stdout to a filepython main.py 80 > logs_`date +%Y%m%d_%H%M%S` 2>&1 &

Install latest #nodejs on raspberry pi (#raspbian)


First add the source:curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -Install just like normal - don’t install node which is different.sudo apt install nodejsNow you can use it just like normal nodejs, this should output something like 7.blahnode -vNPM comes for free as well.npm -v

Solving pip error: ImportError: cannot import name IncompleteRead


$ sudo pip uninstall wheezyTraceback (most recent call last): File "/usr/bin/pip", line 9, in <module> load_entry_point('pip==1.5.6', 'console_scripts', 'pip')() File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 356, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2476, in load_entry_point return ep.load() File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2190, in load ['__name__']) File "/usr/lib/python2.7/dist-packages/pip/__init__.py", line 74, in <module> from pip.vcs import git, mercurial, subversion, bazaar # noqa File "/usr/lib/python2.7/dist-packages/pip/vcs/mercurial.py", line 9, in <module> from pip.download import path_to_url File "/usr/lib/python2.7/dist-packages/pip/download.py", line 25, in <module> from requests.compat import IncompleteReadImportError: cannot import name IncompleteReadJust re-inst...

Complete Guide of Battle.net OAuth API and Login Button


I play Overwatch like crazy and I use sites like overbuff and masteroverwatch.I like their battle.net login buttons and wanted to create a simple site to beat matchmaking system. I didn’t realize that this will be a huge struggle.Here are the official docs:https://dev.battle.net/docs/read/oauthGet this Chrome Extension to try get post requests, amazing extension including authentication features:https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=enSign up first Go to the https://dev.battle.net and create a mashery account. Create your first app You can put localhost as callback url, you MUST put it as https://localhost https is really important let’s keep this in mind. Note your client key and secret and redirect_uri which must be an HTTPS url.Get authorization codeOauth is usually 2-steps. First you authorize the user and then use this authorization to obtain an access token in order to make requests to battle.net on behalf ...

Simplest Raspberry Pi 3 setup as a home server - Jan'17


I’ve just done it and I don’t want to forget this struggle. Buy a super fast 32 gb sd card - keep your adapter because most of the new computers only have sd card slots not micro sd slots. Format sd card as FAT - MSDOS with Disk utility -> Erase on Mac Right click -> Format on Windows Disks on Ubuntu Download NOOBS - easy UI to select which OS should be installed into your pi. Don’t bother flashing yourself with raspbian etc. Extract NOOBS zip and copy all of the files (if it’s extracted into a folder just copy its content, root of the sd card must have a couple of files, not one directory) Put your recently formatted and NOOBs copied sd card into the pi and then wait a little bit Plug your raspberry pi into micro usb Plug your monitor via an HDMI cable Plug your mouse and keyboard (mechanical keyboards take some time though to be recognized, just wait a little bit more) NOOBS UI will show up, for raspberry pi 3 you can connect to wifi. You ca...

Enable SSH access to your fresh Ubuntu install (16.10)


Leaving this here since I should not spend another hour to figure this out in my next fresh ubuntu install.Install ssh server first:sudo apt-get install openssh-server And open the port:sudo ufw allow 22Find your IP addressifconfig

My site is hacked with an interesting method


I have a small Turkish meme site. It’s very simple and easy to maintain.I use cloudflare for caching, SSL and DNS stuff and I love it.However, today I realized that my site started to redirect to some weird site which says some random “Your flash is outdated, please update”. Check chrome network tab - can not see anything because it’s a redirect and all info is gone. Check domain provider - all good Check Cloudflare DNS settings - all goodLast resort I tried to find out the HTTP request call tree.I’m breaking the redirection URL because I don’t want to send them traffic.curl --head guldum.netHTTP/1.1 301 Moved PermanentlyDate: Thu, 19 Jan 2017 17:24:22 GMTConnection: keep-aliveSet-Cookie: __cfduid=d0af6e03ce78a3a99580dc2bbc87c90c31484846662; expires=Fri, 19-Jan-18 17:24:22 GMT; path=/; domain=.guldum.net; HttpOnlyLocation: https://goo.gl/ H41yAyServer: cloudflare-nginxCF-RAY: 323bfadaa6ec3470-LHRIt has a 301 redirection, it immediately popped up in my mind: Page rules. I checked ...

Weekly roundup - 11


Wordpress released .blog extension, get yours with an incredible price. eg. hakan.blog -> 5220 euro, thanks, feeling valued. https://get.blog/ Get Android debug keystore hash (SHA1, SHA256 or MD5) - useful for firebase authentication:keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android Star Citizen 2016 - Gamescom trailer: https://www.youtube.com/watch?v=GucYhhLwIxg Android Nougat 7.0 Official website TheVerge review Yet another betalist clone: http://www.betafy.co/ I needed a Mac’s Preview like image editor to quickly resize/stretch images for Chrome Webstore. I made my logo but it turned out to be 128x127px so I need to make it 128x128px. Spent like 15 minutes. Tried these ones: Geeqie * sudo apt-get install geeqie Gthumb * sudo apt-get install gthumb Shotwell image viewer Nautilus right click context menu resizer * sudo apt-get install p...

Weekly roundup - 10 #pocket #ai #rtos


‘Pink + Purple == Fuchsia (a new Operating System).’ HN discussion They say it’s an OS for augmented reality with predictable latency times like a RTOS. Let’s see. https://fuchsia.googlesource.com/magenta/+show/master/docs/mg_and_lk.md https://github.com/fuchsia-mirror/escher https://fuchsia.googlesource.com/ What we learned from running Fuchsia, the mysterious new OS from Google This week I was sooo annoyed with Pocket so I decided to start a new project. Stay tuned! Meanwhile I tried these ones: Basket Raindrop Flynx’s reader UI Instapaper Problem is that Pocket and these ones have problem with really simple sites like Medium, wikipedia and my favorite eksisozluk.com For the people with lack of color abilities while doing the web design: http://jxnblk.com/hello-color Play MS-Dos games in the browser for free without DosBox https://archi...

Weekly roundup - 9 #sqlite #python #bash


SQLite dump a table as csv: sqlite3 -header -csv mydb.db "select * from my_table;" > monthly.csv See the schema * cat .schema | sqlite3 mydb.db Redirect output to txt file from sqlite cli. * $ sqlite3 mydb.db * `.output my.txt` * `select * from my_table;` * OR just dump the whole db * `$ sqlite3 mydb.db` * `.output my.txt` * `.dump` Bash - check if a command is installed in the machine:command_exists (){ type "$1" &> /dev/null ;}# Install csvtojson if not exists.if command_exists csvtojson ; then echo "csvtojson exists"else echo "Installing csvtojson" sudo npm install -g csvtojsonfi Python multi threading: Pass parameters to the threadimport threadingdef F(): threading.Thread(target=Foo, args=(my_param,)).start()def Foo(my_param): print 'This is a long running process' Jekyll multiline code blocks for github pages (kramdown):```language_namesome_code_here(...


subscribe via RSS