Skip to content

Instantly share code, notes, and snippets.

View stalmok's full-sized avatar

Kestutis Stalmok stalmok

  • Vancouver, Canada
View GitHub Profile
@stalmok
stalmok / flatten.js
Created February 11, 2019 01:34
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers
/**
* Code was written in Javascript (ES6)
* Tests will work only in Node.js environment
*/
/**
* Flatten an array of arbitrarily nested arrays of integers into
* a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
*
* @param {Array} input
@stalmok
stalmok / nginx.config
Last active May 22, 2017 14:24
ebs-meteor
files:
"/etc/nginx/conf.d/custom_config.conf":
content: |
server_tokens off;
client_max_body_size 2M;
"/etc/nginx/sites-available/elasticbeanstalk-nginx-docker-proxy.conf":
content: |
map $http_upgrade $connection_upgrade {
default "upgrade";
@stalmok
stalmok / sync-directory
Created February 8, 2013 14:50
Synchronize directories. With `-n` files aren't actually moved - just prints the expected output of the operation.
rsync -n -u --stats --progress /home/user/test/1/* /home/user/test/2/
@stalmok
stalmok / jpegtran-directory.sh
Last active December 11, 2015 04:39 — forked from rik/jpegtran-directory.sh
Bash: Optimize .jpg images
#!/usr/bin/env bash
function optimize
{
echo $1
filesize=`stat --format=%s "$1"`
if [[ $filesize -lt 10000 ]]; then
jpegtran -copy none -optimize "$1" > "$1.bak"
echo "pet"
else
@stalmok
stalmok / strip-whitespace.js
Created January 6, 2013 16:51
JavaScript: Strip Whitespace From String
// http://css-tricks.com/snippets/javascript/strip-whitespace-from-string/
// Remove leading and trailing whitespace
// Requires jQuery
var str = " a b c d e f g ";
var newStr = $.trim(str);
// "a b c d e f g"
// Remove leading and trailing whitespace
// JavaScript RegEx
@stalmok
stalmok / nginx-check-conf
Created December 21, 2012 16:36
Nginx: test configuration
nginx -t -c /etc/nginx/nginx.conf
@stalmok
stalmok / restrict-access
Created December 5, 2012 15:03
Restrict user access to content in folders using PHP and Apache
/**
* Original post: http://www.thebigblob.com/how-to-restrict-user-access-to-content-in-folders-using-php-and-apache-htaccess-files/
*/
# The .htaccess file
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^\/(path\/to\/some\/folder|dummy)\/.*$
RewriteRule !^((.*.php)|(.*\/))$ authorize.php
@stalmok
stalmok / sql-replace-string
Created November 12, 2012 09:38
MySQL: replace string and update
// replace string and update
update [table_name] set [field_name] = replace([field_name],'[string_to_find]','[string_to_replace]');
@stalmok
stalmok / clear_cache.php
Created November 8, 2012 22:09
Drupal: clear cache
menu_rebuild();
drupal_flush_all_caches();
die();
@stalmok
stalmok / mysql-import
Created October 29, 2012 12:20
MySQL: Import Datafile
mysql -u username -p -h localhost DATA-BASE-NAME < data.sql