Skip to content

Instantly share code, notes, and snippets.

View sergeylukin's full-sized avatar
🎯
Focusing

Sergey Lukin sergeylukin

🎯
Focusing
View GitHub Profile
@sergeylukin
sergeylukin / optimg.sh
Last active July 3, 2019 07:15
Shell script for JPGs and PNGs optimization
#!/usr/bin/env sh
#
# This script automates images optimization
# is mainly used by a developer who manually
# can execute it when adding new images to the
# project
#
# Download and compile following binaries:
#
# - [jpegtran](http://www.ijg.org/)
@sergeylukin
sergeylukin / branch2command.sh
Created June 23, 2013 19:08
Run commands remotely through `git push` - example with 2 levels deployment
#! /usr/bin/env sh
# This script accepts 2 mandatory arguments:
# COMMAND and ENVIRONMENT
#
# It's run by git repo hook and current
# workign directory is the bare repo path
#
# Global variables accessible:
# $WORKTREE (points to the working tree)
#
@sergeylukin
sergeylukin / branch2command.sh
Created June 23, 2013 19:02
Run commands remotely through `git push` - example with 1 level deployment
#! /usr/bin/env sh
# This script accepts 1 mandatory argument:
# COMMAND
#
# It's run by git repo hook and current
# workign directory is the bare repo path
#
# Global variables accessible:
# $WORKTREE (points to the working tree)
#
// This patch changes the way Candle's UP state is detected
// Instead of comparing it to the previous candle, we just compare CLOSE and OPEN
// values here
(function(HC) {
var seriesTypes = HC.seriesTypes;
seriesTypes.candlestick.prototype.getAttribs = function () {
seriesTypes.column.prototype.getAttribs.apply(this, arguments);
@sergeylukin
sergeylukin / awk_vs_grep.sh
Last active December 17, 2015 06:19
Profiling AWK vs GREP in sorting file contents in custom order (AWK is 2 times faster)
#! /usr/bin/env sh
###
### awk_vs_grep.sh - Profiles 2 methods used to sort file contents using custom pattern
### make sure to have file "awk_vs_grep.txt" with some content
### for more details refer to this Question: http://unix.stackexchange.com/questions/75498/sort-using-custom-pattern/
###
### Usage: `./awk_vs_grep.sh` - will execute commands 10 times and only print profile results
### Usage: `./awk_vs_grep.sh 1000` - will execute commands 1000 times and only print profile results
### Usage: `./awk_vs_grep.sh 1000 /dev/tty` - will execute commands 1000 times and print commands output + results
class ServicesController < ApplicationController before_filter :authenticate_user!, :except => [:create] def index # get all authentication services assigned to the current user @services = current_user.services.all end def destroy # remove an authentication service linked to the current user @service = current_user.services.find(params[:id]) @service.destroy redirect_to services_path end def create # get the service parameter from the Rails router params[:service] ? service_route = params[:service] : service_route = 'no service (invalid callback)' # get the full hash from omniauth omniauth = request.env['omniauth.auth'] # continue only if hash and parameter exist if omniauth and params[:service] # map the returned hashes to our variables first - the hashes differ for every service if service_route == 'facebook' omniauth['extra']['user_hash']['email'] ? email = omniauth['extra']['user_hash']['email'] : email = '' omniauth['extra']['user_hash']['name'] ? name = omniaut
@sergeylukin
sergeylukin / xorg.conf
Created November 8, 2012 14:09
FreeBSD X11 configuration file for ThinkPad T60
Section "ServerLayout"
Identifier "X.org Configured"
Screen 0 "Screen0" 0 0
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
EndSection
Section "Files"
ModulePath "/usr/local/lib/xorg/modules"
FontPath "/usr/local/lib/X11/fonts/misc/"
@sergeylukin
sergeylukin / WORKSTATION
Created November 7, 2012 16:36
FreeBSD 9 KERNEL for ThinkPad T60
include GENERIC
# Exclude CPU types
nocpu I486_CPU
nocpu I586_CPU
ident WORKSTATION
# Disable mount partitions from UNIX server over TCP/IP
# Enable when needed
@sergeylukin
sergeylukin / newdraft
Created August 25, 2012 16:50
Ruby script for creating New Draft Post in Jekyll
#!/usr/bin/env ruby
unless ARGV[0]
puts 'Usage: newdraft "the draft title"'
exit(-1)
end
date_prefix = Time.now.strftime("%Y-%m-%d")
post_name = ARGV.join ' '
post_file_name = post_name.strip.downcase.gsub(/ /, '-')
@sergeylukin
sergeylukin / post-update
Created July 25, 2012 10:47
Git hook: deny specific branches to be pushed
#!/bin/sh
# <oldrev> <newrev> <refname>
# sanitize pushed branch
while read oldrev newrev ref
do
branch=$(echo $ref | awk -F'/' '{print $3}')
if [ "$branch" != "master" -a "$branch" != "docs" ]
then
echo It is not allowed to push any branch except for master and docs