Sign up to create your own snipts, or login.

Public snipts » gin's snipts The latest snipts from gin.

showing 1-8 of 8 snipts
  • Get PYTHONPATH content, from bash shell
    # Get PYTHONPATH content, from bash shell
    printf "import sys\nprint sys.path\nquit()\n" | python
    

    copy | embed

    0 comments - tagged in  posted by gin on Jan 21, 2010 at 2:31 p.m. EST
  • search & apply new perm for files in pattern
    #!/bin/bash
    
    # Search for files with pattern name defined on name var, then
    # apply new user, group and other perms. located in path
    
    old_user='gin';
    new_user='shakka';
    
    old_group='guest';
    new_group='geek';
    
    name='*.ogg'
    path='/home/gin/video/';
    perm='700';
    
    	chmod ${perm} `find ${path} -name ${name} -user ${old_user} -group ${old_group}`;
    	chown ${new_user}:${new_group} `find ${path} -name ${name} -user ${old_user} -group ${old_group}`;
    
    exit 0;
    

    copy | embed

    0 comments - tagged in  posted by gin on Jan 05, 2010 at 6:19 p.m. EST
  • set database charset with zend
    <?
    /* Index.php bootstrap application*/
    
    /* Load config data */
    $config = new Zend_Config_Xml('./app/config.xml', 'general');
    $registry = Zend_Registry::getInstance();
    $registry->set('config', $config);
    
    /* Set database */
    $db = Zend_Db::Factory($config->db->def->adapter, $config->db->def->params->toArray());
    Zend_Db_Table::setDefaultAdapter($db);
    
    /* Specify database charset */
    $db->query("SET NAMES 'utf8'");
    $db->query("SET CHARACTER SET 'utf8'");
    

    copy | embed

    0 comments - tagged in  posted by gin on Dec 30, 2009 at 11:29 a.m. EST
  • remove spaces
    #!/bin/bash
    
    # original value
    my_var="Fuck World!";
    
    # trim function
    function trim()
    {
    local _tmp=$@;
    
        _tmp=${_tmp/ /};
        echo $_tmp;
    }
    
        # passing one argument
        new_var=$(trim $my_var);
    
        # modified value, without spaces
        echo $new_var;
    

    copy | embed

    0 comments - tagged in  posted by gin on Dec 11, 2009 at 10:43 a.m. EST
  • clean samba recycle directory every 'x' time
    #!/bin/bash
    
    # clean samba recycle directory every 'x' time
    #
    # cronjob:
    # 0 5 * * * root /usr/local/bin/recyclean.sh
    
    path="/home/samba/.recycle/"
    days="20"
    
    rm -rf `find ${path} -mtime +${days} -print`;
    

    copy | embed

    0 comments - tagged in  posted by gin on Oct 26, 2009 at 3:31 p.m. EDT
  • run banshee from ssh session
    #!/bin/sh
    # run banshee from ssh session & auto play queque
    
    export DISPLAY=:0
    dbus-launch /usr/bin/banshee --play
    

    copy | embed

    0 comments - tagged in  posted by gin on Oct 26, 2009 at 3:21 p.m. EDT
  • get info from selected drop box
    /* Get info from selected drop box
     * Javascript Common tools
     * Moises Brenes moises.brenes@gmail.com
     */
    function get_selected(id)
    {
    var selected, value, text;
    	
    	value = null;
    	text = null;
    	
    	/* id item selected */
    	selected = document.getElementById(id).selectedIndex;
    	
    	if (selected >= 0)
    	{
    		value = document.getElementById(id).options[selected].value;
    		text = document.getElementById(id).options[selected].text;
    	}
    
    	if (selected < 0)
    		selected = null;
    
    return [selected, value, text];
    }
    

    copy | embed

    0 comments - tagged in  posted by gin on Aug 24, 2009 at 7:09 p.m. EDT
  • alien number generator
    /* Alien Numbers
     * Google Code Jam, Practice 2009
     * Moises Brenes moises.brenes@gmail.com
     */
    #include <cstdlib>
    #include <string>
    #include <cmath>
    #include <vector>
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    /* explode a string */
    void split(string src, string del, vector<string> *dst)
    {
    int found;
    
    	found = src.find_first_of(del);
    	while (found != string::npos)
    	{
    		if (found > 0)
    			dst->push_back(src.substr(0, found));
    		
    		src = src.substr(found + 1);
    		found = src.find_first_of(del);
    	}
    	
    	if (src.length() > 0)
    		dst->push_back(src);
    }
    
    /* convert a string from any base to any base  */
    string convert(string alien, string source, string target)
    {
    string str;
    int a_size;
    int s_size;
    int t_size;
    int dec;
    int i;
    
    	/* alien number size */
    	a_size = alien.size();
    	/* source language base */
    	s_size = source.size();
    	/* target language base */
    	t_size = target.size();
    	
    	str = "";
    	dec = 0;
    	
    	/* convert x base to decimal */
    	for (i = 0; i < a_size; i++)
    		dec = dec + (source.find_first_of(alien[i]) * pow(s_size, a_size - 1 - i));
    	
    	/* convert decimal to y base */
    	while (dec != 0)
    	{
    		str = (target[dec % t_size] + str);
    		dec = (int) (dec / t_size);
    	}
    	
    return str;
    }
    
    int main(int argc, char **argv)
    {
    char buffer[256];
    int i;
    int top;
    ifstream input;
    string str;
    vector<string> field;
    
    	if (argc == 2)
    	{
    		input.open(argv[1]); 
    
    		input.getline(buffer, 256);
    		str = (string) buffer;
    		
    		i = 1;
    		top = atoi(str.c_str());
    		do
    		{
    			input.getline(buffer, 256);
    			str = (string) buffer;
    			
    			if (i <= top)
    			{
    				split(str, " ", &field);
    				
    				cout << "Case #" << i << ": " << convert(field[0], field[1], field[2]) << endl;
    				
    				field.erase(field.begin(),field.end());
    			}
    			
    			i++;
    		}
    		while (!input.eof());
    		
    		input.close();
    	}
    
    return 0;
    }
    

    copy | embed

    0 comments - tagged in  posted by gin on Aug 24, 2009 at 2:38 p.m. EDT
Sign up to create your own snipts, or login.