Skip to content

Instantly share code, notes, and snippets.

View f0t0n's full-sized avatar

Eugene Naydenov f0t0n

View GitHub Profile
@f0t0n
f0t0n / num2bin.py
Created February 24, 2012 22:33
Convert an integer number to another system - such as to binary, hex, etc. (Python example)
#!/usr/bin/env python
from itertools import chain
from sys import exit
def num_to_bin():
try:
original_number = int(input('Chose the number: '))
basis = int(input('Chose the basis (up to 32): '))
if(basis > 32):
@f0t0n
f0t0n / gist:2304163
Created April 4, 2012 17:39
lorem ipsum for chartus editor
$(document).on('chartusEditor.load', function() {
var paragraphsCount = 2,
loremIpsum = new goog.text.LoremIpsum();
loremParagraphs = [];
for(var i = 0; i < paragraphsCount; i++) {
loremParagraphs.push(
'<p>', loremIpsum.generateParagraph(), '</p><br />'
);
}
window.ChartusEditor.setHtml(
@f0t0n
f0t0n / gist:2312748
Created April 5, 2012 17:36
Common setup database connection configuration for Yii framework
<?php
return array(
'connectionString' => 'mysql:host=localhost;dbname=YOUR_DATABASE_NAME',
'emulatePrepare' => true,
'username' => 'YOUR_DATABASE_USERNAME',
'password' => 'YOUR_DATABASE_PASSWORD',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
'enableProfiling' => true,
);
@f0t0n
f0t0n / gist:2360436
Created April 11, 2012 16:40
dir. name to ascii
<?php
header('Content-Type: text/plain; charset=ISO-8859-1');
ini_set('memory_limit', '512M');
ini_set('max_execution_time', '0');
defined('DS') OR define('DS', DIRECTORY_SEPARATOR);
setlocale(LC_ALL, 'en_US.ISO-8859-1');
function clearUTF($s) {
$r = '';
$s1 = iconv('ISO-8859-1', 'ASCII//TRANSLIT', $s);
for ($i = 0; $i < strlen($s1); $i++) {
@f0t0n
f0t0n / cuseragent.php
Created April 22, 2012 11:14
Generates a random UserAgent string
<?php
$userAgents = array(
// Mozilla Firefox:
'Mozilla/5.0 (X11; Linux i686; rv:2.0) Gecko/20100101 Firefox/4.0',
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101211 Namoroka/3.6.13',
'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101230 Mandriva Linux/1.9.2.13-0.2mdv2010.2 (2010.2) Firefox/3.6.13',
'Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13',
// Google Chrome:
'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_6; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.133 Safari/534.16',
'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.1 (KHTML, like Gecko) Chrome/5.0.322.2 Safari/533.1',
@f0t0n
f0t0n / curl.php
Created April 22, 2012 11:20
Using php curl with CURLOPT_USERAGENT option
<?php
$username='h2odev';
$password='likewater';
$location='http://h2odev.law.harvard.edu/playlists/151';
$baseUrl = 'http://h2odev.law.harvard.edu/';
$currDir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
$userAgent = require($currDir . 'cuseragent.php');
$ch = curl_init ();
@f0t0n
f0t0n / gist:2537918
Created April 29, 2012 07:04
The dialog window's behavior is too stupid.
<?php
/**
* In /protected/views/book/view.php ln. 52
*/
$this->widget('ext.widgets.jui.JuiDialog', array(
'id'=>'book-dialog',
// additional javascript options for the dialog plugin
'options'=>array(
'title'=>'Dialog box 1',
'autoOpen'=>false,
@f0t0n
f0t0n / importdb.php
Created April 30, 2012 11:30
import db config
<?php
return array(
'connectionString' => 'mysql:host=localhost;dbname=book_import_db',
'emulatePrepare' => true,
'username' => 'sp1222',
'password' => '2221ps',
'charset' => 'utf8',
'tablePrefix' => 'tbl_',
'enableProfiling' => true,
'class'=>'CDbConnection',
@f0t0n
f0t0n / node.php
Created April 30, 2012 11:49
Chartus Node.JS client-application configuration file
<?php
return array(
'turned-on'=>false,
'port'=>28000,
'notifications'=>array(
'turned-on'=>false,
)
);
{
"kind": "books#volumes",
"totalItems": 1215,
"items": [
{
"kind": "books#volume",
"id": "W5lvCBqgPGkC",
"etag": "e587On094FY",
"selfLink": "https://www.googleapis.com/books/v1/volumes/W5lvCBqgPGkC",
"volumeInfo": {