Skip to content

Instantly share code, notes, and snippets.

Kestutis Stalmokas stalmok

  • Vancouver, Canada
Block or report user

Report or block stalmok

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@stalmok
stalmok / flatten.js
Created Feb 11, 2019
Flatten an array of arbitrarily nested arrays of integers into a flat array of integers
View flatten.js
/**
* 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
View nginx.config
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 Feb 8, 2013
Synchronize directories. With `-n` files aren't actually moved - just prints the expected output of the operation.
View sync-directory
rsync -n -u --stats --progress /home/user/test/1/* /home/user/test/2/
@stalmok
stalmok / jpegtran-directory.sh
Last active Dec 11, 2015 — forked from rik/jpegtran-directory.sh
Bash: Optimize .jpg images
View jpegtran-directory.sh
#!/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 Jan 6, 2013
JavaScript: Strip Whitespace From String
View strip-whitespace.js
// 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 Dec 21, 2012
Nginx: test configuration
View nginx-check-conf
nginx -t -c /etc/nginx/nginx.conf
@stalmok
stalmok / restrict-access
Created Dec 5, 2012
Restrict user access to content in folders using PHP and Apache
View restrict-access
/**
* 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 Nov 12, 2012
MySQL: replace string and update
View sql-replace-string
// 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 Nov 8, 2012
Drupal: clear cache
View clear_cache.php
menu_rebuild();
drupal_flush_all_caches();
die();
@stalmok
stalmok / mysql-import
Created Oct 29, 2012
MySQL: Import Datafile
View mysql-import
mysql -u username -p -h localhost DATA-BASE-NAME < data.sql
You can’t perform that action at this time.