Skip to content

Instantly share code, notes, and snippets.

@mrded
mrded / gist:e5e8191d44f99725eb08
Last active August 29, 2015 14:04
AngularJS: Initial
angular.element(document).ready(function() {
var $inj = angular.bootstrap(document.body, ['use']);
var $rootScope = $inj.get("$rootScope");
$rootScope.$broadcast("init", "hello");
$rootScope.$digest();
});
@mrded
mrded / team.html
Last active August 29, 2015 14:04
ttlApp: Templates
<div ng-app="mcApp">
<div ng-controller="TeamCtrl">
<h1>{{team.name}}</h1>
<hr>
<div class='row'>
<div class='col-sm-4'>
<mc-user ng-repeat="user in users.slice(0, users.length / 3) | filter:{team_ids: team.id}"></mc-user>
</div>
@mrded
mrded / machine_name.php
Created July 15, 2014 13:16
PHP: make machine name from string
<?php
$machine_name = preg_replace('@[^a-z0-9-]+@', '-', strtolower($string));
@mrded
mrded / gist:692491d35a8f3a41be35
Created July 10, 2014 19:47
AngularJS: $scope.$apply
$scope.$$phase || $scope.$apply(function() {
$scope.todos = todos;
});
@mrded
mrded / foo.module
Created July 10, 2014 09:59
Drupal 7: Overwrite views on the fly
<?php
/**
* Implements hook_views_pre_view().
*/
function HOOK_views_pre_view(&$view, &$display_id, &$args) {
if ($view->name == 'company_contents') {
$company_node = menu_get_object();
if (!empty($company_node->field_contract_period[LANGUAGE_NONE][0])) {
@mrded
mrded / geocoder.module
Created June 26, 2014 14:15
Drupal 7: Get location object by address string.
<?php
/**
* Get location object by address string.
*
* @param string $location
*
* @return array
*
* @dependencies geocoder module.
*/
@mrded
mrded / foo.module
Created June 25, 2014 16:48
Drupal 7: FQL get user's current_location
<?php
$access_token = 'woknfowenf';
$query = 'SELECT blabla... FROM blabla...';
$result = fboauth_graph_query('fql', $access_token, array('q' => $query));
@mrded
mrded / module.php
Created June 16, 2014 10:07
Drupal 7: Entity metadata wrappers
<?php
//@see: https://drupal.org/node/1021556
$wrapper = entity_metadata_wrapper('node', $node);
$wrapper->author->mail->value();
$wrapper->author->mail->set('[email protected]');
$wrapper->author->mail = '[email protected]';
// Unified way of getting $node->title, $user->name, ...
@mrded
mrded / backend.module
Created June 12, 2014 10:56
Drupal 7: Show ctools modal via JS.
<?php
drupal_add_js('misc/ajax.js');
ctools_add_js('modal');
ctools_add_css('modal');
// Add your modal style to the settings. You find the defaults in modal.js near the top:
drupal_add_js(array(
'my-modal-style' => array(
'modalSize' => array(
@mrded
mrded / controllers.js
Last active August 29, 2015 14:02
AngularJS: Version with global variables.
app.controller('mainCtrl', function($rootScope, UserService) {
$rootScope.users = [];
$rootScope.todos = [];
// Get all users.
UserService.all().then(function(users) {
angular.forEach(users, function(user) {
$scope.users.push(user);
// Get all todos.