Skip to content

Instantly share code, notes, and snippets.

View tsertkov's full-sized avatar
🖐️
Say Hello

Aleks Tsertkov tsertkov

🖐️
Say Hello
View GitHub Profile
@tsertkov
tsertkov / switch_variables_values.js
Created May 14, 2014 08:01
Switch values of two variables without creating intermediate buffer variable
var a = 1, b = 2;
a = [b, b = a][0];
@tsertkov
tsertkov / nginx_image_filter.conf
Last active August 29, 2015 14:02
On the fly image resizing with image_filter
# On the fly resizing of images inside /images/*/
# based on query string "width" and "height" parameters
location ~ /images/(.+)/ {
set $width -;
set $height -;
set $entity $1;
if ($arg_width) {
set $width $arg_width;
@tsertkov
tsertkov / nginx_inherit_dir.conf
Created July 6, 2014 20:07
Search files in multiple folders within same location
server {
listen 80;
server_name example.com;
root /data/public;
location / {
try_files $uri @fallback;
}
location @fallback {
@tsertkov
tsertkov / download_linked_html_resources.sh
Created July 31, 2014 08:35
Extract src arguments value from input file and download them
#!/usr/bin/env sh
INPUT="$1"
sed -n 's/.* src="\(https:\/\/.*\)".*/\1/p' "$INPUT" | xargs -I {} curl -O {}
@tsertkov
tsertkov / mongo_shell_sshtunnel.sh
Created July 31, 2014 09:32
Connect to mongo over ssh tunnel
#!/usr/bin/env sh
# In this example mongod runs in vagrant box
# do not be confused about ssh arguments
ssh \
-N -p 2222 -l docker \
-i ~/.vagrant.d/insecure_private_key \
-L localhost:27017:localhost:27017 \
127.0.0.1 &
@tsertkov
tsertkov / iphone_retina_image.css
Created August 1, 2014 10:19
Responsive retina images for iphone
/* iPhone with no retina display */
@media screen {
body {
background-image: url("../img/background.png");
}
}
/* iPhone < 5 and retina display */
@media screen and (device-height: 480px) and (-webkit-min-device-pixel-ratio: 2) {
body {
@tsertkov
tsertkov / file_time.sh
Created August 2, 2014 16:29
Get file last modification time
#!/usr/bin/env sh
FILE="$1"
stat -f "%Sm" -t "%y%m%d-%H%M%S" "$FILE"
@tsertkov
tsertkov / nc_local_port_forward.sh
Created August 13, 2014 14:27
Forward localhost port onto public interface
// FIXME Works only for firs connected client...
nc -l -p 5859 -c "nc 127.0.0.1 5858"
@tsertkov
tsertkov / enable_swap.sh
Created August 25, 2014 12:53
Enable swap on Linux
#!/usr/bin/env sh
SIZE="${1}G"
fallocate -l "$SIZE" /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile\t none\t swap\t sw\t 0\t 0" >> /etc/fstab
@tsertkov
tsertkov / dereference_var.sh
Created October 2, 2014 13:55
Dereference shell variable
START="start"
END="end"
VALUE="VALUE"
START_VALUE_END="start_value_end"
VAR=$(eval echo "\$START_${VAR}_END")
echo $VAR
# VAR = "start_value_end"