Skip to content

Instantly share code, notes, and snippets.

View Kein1945's full-sized avatar
:octocat:
Happening some things.

Kein Kein1945

:octocat:
Happening some things.
  • Bali
View GitHub Profile
@Kein1945
Kein1945 / gist:9546472
Created March 14, 2014 12:05
Javascript console snippet for fast add many url's to pocket. Run from chrome debugger console(ctrl+shift+J)
// formCheck - global variable token from page
// Enter in prompt articles url with new line delemiter
var _add = function (url){
$.ajax({
url: 'http://getpocket.com/a/x/itemAction.php'
,data:{
action: 'add'
,formCheck: formCheck
, url: url
}
@Kein1945
Kein1945 / home_contorller.rb
Created May 11, 2014 11:39
Send emails in RoR via pdd.yandex.ru
class HomeController < ApplicationController
def contacts
UserMailer.notify_email( params[:text]).deliver
end
end
@Kein1945
Kein1945 / navigation.html.twig
Created April 15, 2013 10:31
Navigation snippet for #Symfony2 #Twig #Twitter bootstrap
{% set menu = {
'products_dashboard' : 'Products'
} %}
<ul class="nav">
{% for path,label in menu %}
<li{% if path(path) in app.request.RequestUri %} class="active"{% endif %}><a href="{{ path(path) }}">{{ label }}</a></li>
{% endfor %}
</ul>
@Kein1945
Kein1945 / gist:6401324
Created August 31, 2013 23:31
Javascript String format
String.prototype.format = function() {
var i = -1, args = arguments;
return this.replace(/#\{(.*?)\}/g, function(one, two) {
return (typeof args[0] == 'object')?args[0][two]:args[++i];
});
}
var thing = 'world!';
@Kein1945
Kein1945 / backbone_logging.js
Last active December 25, 2015 18:19
Simple function that allow see events flow in dev console with stack trace and data.
var bind_logging = (function(strategies, loggers) {
var log_always = '#bind_logging' == document.location.hash;
var canWeLogThis = function(eventflow) {
return _.every(['on', 'off', 'trigger'], function(n){ return eventflow && _.isFunction(eventflow[n]) });
},
canWeLogHere = function() {
return _.every(['groupCollapsed', 'groupEnd', 'log', 'trace'], function(n){ return console && _.isFunction(console[n]) });
},
getLogger = function(ctx, args) {
for(var i = 0; i < strategies.length; i++) {
@Kein1945
Kein1945 / gist:7524410
Created November 18, 2013 08:16
Chrome dev tool snippet for print forms detail info
[].forEach.call(document.querySelectorAll('form'), function (input) {
var table = [];
console.group('HTMLForm "' + input.name + '": ' + input.action);
console.log('Element: ', input, '\nName: ' +
input.name + '\nMethod: ' + input.method.toUpperCase() +
'\nAction: ' + input.action || 'null');
['input', 'textarea', 'select'].forEach(function (control) {
[].forEach.call(input.querySelectorAll(control), function (node) {
@Kein1945
Kein1945 / wait_until_hosts.sh
Last active December 30, 2015 12:12
Simple bash script that waiting hosts in environment. Usable with docker compose, when some containers not started and we doesn't have some host in environment.
#!/bin/bash
hosts=( "$@" )
total_hosts=${#hosts[@]}
while :
do
l_hosts=( ${hosts[@]} )
for i in ${!l_hosts[@]}
do
@Kein1945
Kein1945 / .bashrc
Last active January 11, 2017 11:36
Bashrc script for remote working
# Usage
# $ source /dev/stdin < <(curl url.this.bashrc)
PS1=$'\[\033]0;\u:${PWD##*/}\007\]'
PS1+=$'\[\e[0;32m\]\u\[\e[m\]\[\e[0;32m\]@\H\[\e[m\] \[\e[0;30;42m\] [home +\j] \[\e[m\]'
PS1+=$'\n\[\e[0;34m\]\w\[\e[m\] \[\e[0;32m\]\xe2\x98\x85\[\e[m\] \[\e[0;37m\] '
@Kein1945
Kein1945 / import_db.sh
Created December 3, 2016 20:02
Allow copy remote database to local mysql database throw ssh
#!/usr/bin/bash
mysql -u user -e 'DROP DATABASE IF EXISTS db_dev; CREATE DATABASE db_dev;'
ssh hlts -C -o CompressionLevel=9 'mysqldump -udeploy --password=password \
--skip-lock-tables \
crm | gzip -9 -c' | gunzip | mysql -u root db_dev
@Kein1945
Kein1945 / .bashrc
Last active January 11, 2017 11:37
Bashrc with great fucking advice prompt, git branch, xterm title
ssh_mount_dir='servers/'
export TERM=xterm-256color
export EDITOR="vim"
export CDPATH=:..:~/$ssh_mount_dir:~
if [[ $- != *i* ]] ; then
return
fi