Skip to content

Instantly share code, notes, and snippets.

@graceman9
graceman9 / gist:2f912b28e6c8aecf4421
Last active August 29, 2015 14:05
PHP: get whole and fraction parts of decimal value
<?php
/**
* See:
* http://stackoverflow.com/questions/6619377/how-to-get-whole-and-decimal-part-of-a-number
*/
// get whole and fraction parts of decimal value
$amount = 1.25;
$whole = floor($amount); // 1
$fraction = $amount - $whole; // .25
?>
@graceman9
graceman9 / gist:d692952204937db5125b
Last active August 29, 2015 14:05
Drupal 7: custom data caching - static variables, cache_set()/cache_get()
<?php
/**
* See:
* https://www.lullabot.com/blog/article/beginners-guide-caching-data-drupal-7
*/
// example 1
function my_module_function() {
$my_data = &drupal_static(__FUNCTION__);
@graceman9
graceman9 / gist:fb9110ea00e6dc572c30
Created August 8, 2014 07:24
Drupal 7: create node_types select options, form api
<?php
// node_types select options
$types = node_type_get_types();
foreach($types as $node_type) {
$options[$node_type->type] = $node_type->name;
}
$form['onpay']['onpay_node_types'] = array(
'#type' => 'select',
'#title' => t('Node types'),
'#options' => $options,
@graceman9
graceman9 / node--gift.js
Last active August 29, 2015 14:05
Onpay (my custom module) with jquery.ui.dialog integration for node view page
(function($) {
$(function(){
// jquery.ui.dialog init
$('.onpay-form').dialog({
autoOpen: false,
show: {
effect: 'slideDown',
duration: 100
},
@graceman9
graceman9 / gist:e906e958858a465009b1
Last active August 29, 2015 14:05
Drupal 7: form api options from specific entity (node_type)
<?php
$entity_type = 'node';
$bundle_name = 'gift';
$fields = field_info_instances($entity_type, $bundle_name);
$options = array();
foreach ($fields as $name => $field) {
$options[$name] = $field['label'];
}
$form['field_price'] = array(
'#type' => 'select',
@graceman9
graceman9 / gist:f52968eb9aa5abab68a9
Created August 20, 2014 09:44
Как решить любую задачу используя интернет
Вопрос: Как решить любую задачу?
Преамбула:
Быстрый способ, касается как компьютерных так и бытовых задач.
Тоесть это для тех кто стремиться к эффективности в своей жизни.
Дело в том что человечество накопило массу знаний, а в последнее время они ещё и хорошо организованы и легко находимы.
Многие из наших действий, как это ни странно может показаться, типичны.
Конечно же это касается тех действий, которые легко понять "в теории", и использовать знания для практики.
Ответ: Гугл!
@graceman9
graceman9 / gist:97b0d49b2dc88f04f138
Last active August 29, 2015 14:05
Drupal 7 create node programmatically
<?php
/**
* Drupal 7 create node programmatically.
*
* @see https://www.drupal.org/node/1173136, important! - read comments below post.
*
* also @see http://www.lightrains.com/blog/programmatically-create-node-drupal-7, better explanation.
* also @see http://fooninja.net/2011/04/13/guide-to-programmatic-node-creation-in-drupal-7/
*/
@graceman9
graceman9 / gist:f934ad43139b9fe87e5d
Last active August 29, 2015 14:05
openserver, xdebug, xcallgraph
openserver, xdebug, xcallgraph
xdebug.profiler_enabled=1
@graceman9
graceman9 / template.php
Last active August 29, 2015 14:05
Drupal 7: How to completely theme form (or webform)
<?php
require_once 'template.theme_webform.inc';
/**
* Implements hook_preprocess_HOOK(), form.
*/
function web_preprocess_webform_form(&$variables) {
if ($variables['form']['#form_id'] == 'webform_client_form_72') {
$form = &$variables['form'];

Keybase proof

I hereby claim:

  • I am graceman9 on github.
  • I am gm9 (https://keybase.io/gm9) on keybase.
  • I have a public key ASDdlUqgJ03sh8MIyv2jD2PnjqQ6eCtXu-qJo7pwaWLTpAo

To claim this, I am signing this object: