Skip to content

Instantly share code, notes, and snippets.

View anvyst's full-sized avatar
⌨️
Brewing code

Andrey Vystavkin anvyst

⌨️
Brewing code
View GitHub Profile
@anvyst
anvyst / bash
Created June 27, 2022 12:43
git-remove-local-non-master-branches
git branch | grep -v "master" | xargs git branch -D
@anvyst
anvyst / country-list.hbs
Created August 22, 2016 14:18
Using JCF options in multiple Select elements with Ember
{{#x-select class='input2-style' name='country' value=countryValue id='input2-select' }}
{{#each-in countries as |code country|}}
{{#x-option value=code}} {{country}} {{/x-option}}
{{/each-in}}
{{/x-select}}
@anvyst
anvyst / mysql_dump_excluding_tables.sh
Created October 5, 2015 10:30
Mysqldump excluding certain tables from the dump
#!/bin/bash
PASSWORD=XXXXXX
HOST=XXXXXX
USER=XXXXXX
DATABASE=databasename
DB_FILE=dump.sql
EXCLUDED_TABLES=(
table1
table2
@anvyst
anvyst / phing.cakephp.xml
Created October 21, 2014 13:11
Force Phing to Fail on CakePHP tests
<target name="caketest-local" description="Run CakePHP unit tests with PHPUnit and print human readable output.">
<exec dir="${basedir}" executable="${basedir}/app/Console/cake" output="${logdir}/caketest.log" returnProperty="test_result">
<arg line="test" />
<arg line="--stderr"/>
<arg line="--configuration=${basedir}/phpunit-coverage-text.xml" />
<arg line="app" />
<arg line="AllTests" />
</exec>
<if>
<not>
@anvyst
anvyst / outdated.html
Created August 29, 2014 12:42
stop using outdated IE
<!--[if lt IE 7]>
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
<![endif]-->
@anvyst
anvyst / gzip_import.sh
Created August 19, 2014 07:21
mysql gzip import
gunzip < database.sql.gz | mysql -u user -p database
@anvyst
anvyst / punycode.rb
Last active August 29, 2015 13:57
A quick script for fast conversion of punycode from/to ascii and unicode
#!/usr/bin/env ruby -w
require 'simpleidn'
require 'getoptlong'
opts = GetoptLong.new(
[ '--help', '-h', GetoptLong::NO_ARGUMENT ],
[ '--unicode', '-u', GetoptLong::REQUIRED_ARGUMENT ],
[ '--ascii', '-a', GetoptLong::REQUIRED_ARGUMENT ]
)
@anvyst
anvyst / copypaste_row.sql
Created February 10, 2014 14:41
Copy-paste specific row in MySQL
# YOURID - source record
# yourtable - target table;
CREATE TEMPORARY TABLE tmp_table SELECT * FROM yourtable WHERE id=YOURID;
SELECT @new_id:=((SELECT id FROM yourtable ORDER BY id DESC LIMIT 1) + 1);
UPDATE tmp_table SET id=@new_id WHERE id =YOURID;
INSERT INTO yourtable SELECT * FROM tmp_table WHERE id=@new_id;
@anvyst
anvyst / sinatra_minimal.rb
Created December 20, 2013 08:07
sinatra in less then 999B
%w.rack tilt date INT TERM..map{|l|trap(l){$r.stop}rescue require l};$u=Date;$z=($u.new.year + 145).abs;puts "== Almost Sinatra/No Version has taken the stage on #$z for development with backup from Webrick"
$n=Module.new{extend Rack;a,D,S,q=Rack::Builder.new,Object.method(:define_method),/@@ *([^\n]+)\n(((?!@@)[^\n]*\n)*)/m
%w[get post put delete].map{|m|D.(m){|u,&b|a.map(u){run->(e){[200,{"Content-Type"=>"text/html"},[a.instance_eval(&b)]]}}}}
Tilt.mappings.map{|k,v|D.(k){|n,*o|$t||=(h=$u._jisx0301("hash, please");File.read(caller[0][/^[^:]+/]).scan(S){|a,b|h[a]=b};h);v[0].new(*o){n=="#{n}"?n:$t[n.to_s]}.render(a,o[0].try(:[],:locals)||{})}}
%w[set enable disable configure helpers use register].map{|m|D.(m){|*_,&b|b.try :[]}};END{Rack::Handler.get("webrick").run(a,Port:$z){|s|$r=s}}
%w[params session].map{|m|D.(m){q.send m}};a.use Rack::Session::Cookie;a.use Rack::Lock;D.(:before){|&b|a.use Rack::Config,&b};before{|e|q=Rack::Request.new e;q.params.dup.map{|k,v|params[k.to_sym]=v}}}
#!/bin/bash
####
# Split MySQL dump SQL file into one file per table
# based on http://blog.tty.nl/2011/12/28/splitting-a-database-dump
####
if [ $# -lt 1 ] ; then
echo "USAGE $0 DUMP_FILE [TABLE]"
exit