Skip to content

Instantly share code, notes, and snippets.

View Hagith's full-sized avatar
👨‍💻
Working from home

Rafał Gałka Hagith

👨‍💻
Working from home
View GitHub Profile
@Hagith
Hagith / bash_notes.sh
Last active August 29, 2015 13:56
Bash notes
# count lines in directory
find . -type f ! -path "\.git" ! -path "./CMakeFiles/*" | xargs wc -l
# du of hidden directories
du -hs .[^.]*
du -s .[^.]* | sort -nr
# mirror apache listing
wget --execute="robots = off" --mirror --convert-links --no-parent -R index.html [http://example.com/path/to/dir]
find -name "index.html*" -exec rm {} \;
@Hagith
Hagith / package.json
Created March 20, 2014 12:29
Simple Socket.io server for chat-like communication.
{
"name": "Socket",
"description": "Simple Socket.io server for chat-like communication.",
"version": "0.1.0",
"main": "server.js",
"dependencies": {
"socket.io": "~0.9.16"
}
}
@Hagith
Hagith / gallery-scroll.php
Last active August 29, 2015 14:02
Simple gallery with continuous scroll
@Hagith
Hagith / arrayConditionToString.php
Last active December 15, 2015 19:09
Convert array condition (similar to mongo where) to SQL where clause.
<?php
function arrayConditionToString(array $def, array &$parts = array(), $operator = 'AND')
{
foreach ($def as $k => $v) {
if (is_string($v) && 0 === strpos($v, ':')) {
$parts[] = ' (' . $v . ') ';
}
@Hagith
Hagith / lftpsync
Created April 5, 2013 07:54
Sync files over network
## LFTP
lftp -c "set ftp:list-options -a;
open ftp://${FTP_USER}:${FTP_PASSWD}@${FTP_HOST};
lcd ${SOURCE_PATH};
cd ${DEST_PATH};
mirror --reverse \
--delete \
--verbose \
--ignore-time \
@Hagith
Hagith / website-mirror.sh
Created April 11, 2013 12:54
Create a mirror of a website with Wget
#!/bin/bash
if [[ '' == $1 || '' == $2 ]]; then
echo "Provide domain name and URL"
exit 1
fi
wget \
--recursive \
--no-clobber \
@Hagith
Hagith / ajax2xmlhttprequest.js
Created August 20, 2013 08:02
Simple $.ajax to XMLHttpRequest
jQuery.ajax = function(opts) {
var xhr = new XMLHttpRequest({mozSystem: true});
var method = opts.type || 'GET';
method = method.toUpperCase();
if ('POST' !== method && opts.data) {
opts.url += '?' + jQuery.param(opts.data);
}
xhr.open(method.toUpperCase(), opts.url);
xhr.responseType = opts.dataType || 'json';
xhr.onreadystatechange = function () {
@Hagith
Hagith / tizen.js
Created September 4, 2013 10:18
Tizen init
document.querySelector('body').classList.add('tizen');
if (!window.indexedDB) {
window.indexedDB = window.webkitIndexedDB;
}
if (!window.MutationObserver) {
window.MutationObserver = window.WebKitMutationObserver;
}
document.addEventListener('tizenhwkey', function(e) {
@Hagith
Hagith / blob_base64.js
Created September 11, 2013 10:19
blob <-> base64
var data = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua." ;
var blob = new Blob([data], {
type : "text/plain"
//type : "text/plain; charset=x-user-defined"
//type : "text/plain; charset=utf8"
});
blobToBase64(blob, function(b64) { // convert BLOB to BASE64
var newBlob = base64ToBlob(b64) ; // convert BASE64 to BLOB
$('body').html(blob.size + " != " + newBlob.size) ;
@Hagith
Hagith / cli.sh
Created September 13, 2013 14:25
grunt
web-build ./ -e "node_modules*" -e "nbproject*" -e ".git*" -e "Gruntfile.js" -e "package.json" -e "/.*" --output .build ./
cd .build/
web-signing -p r.galka
web-packaging -o -n ../shabetteconcier.wgt ./
web-install -w widget.wgt