Skip to content

Instantly share code, notes, and snippets.

View boo1ean's full-sized avatar
🎯
Focusing

Egor Gumenyuk boo1ean

🎯
Focusing
View GitHub Profile
@boo1ean
boo1ean / gist:2971633
Last active October 6, 2015 09:18
Basic user management in *nix
# Create new user - useradd
# -s SHELL : The name of the user's login shell
# -m : Create user’s home directory if it does not exist
# -d HOME_DIR : Home directory of the new user
# -c COMMENT : Some description of user
# -g GROUP : Group name of the new user
# USERNAME : Name of the new user
#
# And here is an example:
@boo1ean
boo1ean / gist:3038626
Created July 3, 2012 09:00
Available ActiveSupport data types
# Check out Rails::Generators::GeneratedAttribute::default
when :integer then 1
when :float then 1.5
when :decimal then "9.99"
when :datetime, :timestamp, :time then Time.now.to_s(:db)
when :date then Date.today.to_s(:db)
when :string then name == "type" ? "" : "MyString"
when :text then "MyText"
when :boolean then false
@boo1ean
boo1ean / gist:3742504
Created September 18, 2012 10:34
Unix tail with following and line numbering
tail -f filename.ext | nl
@boo1ean
boo1ean / gist:3789171
Last active October 11, 2015 02:28
Delay callback for typehead
var delay = (function() {
var timer = 0;
return function(callback, ms) {
if (typeof(callback) == 'function' && typeof(ms) == 'number') {
clearTimeout(timer);
timer = setTimeout(callback, ms);
}
}
})();
@boo1ean
boo1ean / gist:3878870
Created October 12, 2012 11:54
Pluralize words javascript
// Original source http://lummie.co.uk/javascript-%E2%80%93-rails-like-pluralize-function/
var pluralize = (function() {
var Inflector = {
Inflections: {
plural: [
[/(quiz)$/i, "$1zes" ],
[/^(ox)$/i, "$1en" ],
[/([m|l])ouse$/i, "$1ice" ],
[/(matr|vert|ind)ix|ex$/i, "$1ices" ],
@boo1ean
boo1ean / gist:3905645
Created October 17, 2012 13:58
Extend php include path
<?php
set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../../libraries/'),
realpath(APPLICATION_PATH . '/../../etc/'),
// ...
// Some other stuff
// ...
get_include_path()
@boo1ean
boo1ean / gist:3905811
Created October 17, 2012 14:28
Code conventions

General

PHP code must always be delimited by the full-form, standard PHP tags and be terminated with semicolon:

<?php
    $model = $web->getModel();
    $title = $model->getTitle();
?>

For single-line statements:

for filename in list
do (filename) ->
# ...
<?php
//User role checking for contacts
$contacts = 0;
$type = explode(',',$data['sp_user_type']);
$contactsArray = array('1','2','3','4','5','6','7','8','9','10');
foreach($contactsArray as $contactsArr){
if(in_array($contactsArr,$type)){
$contacts = 1 ;
}
@boo1ean
boo1ean / gist:4175158
Created November 30, 2012 11:08
Tricky switch
<?php
switch (true) {
case ($a > $b):
//...
break;
case ($a > $c):
//...
break;