Skip to content

Instantly share code, notes, and snippets.

@mrded
mrded / import_dump.sh
Last active August 29, 2015 14:11
mysql: Import database with truncated tables.
#!/bin/bash
# Usage:
# $ bash import-dump.sh http://example.co.uk/dump.sql.gz
start=$(date +"%s")
echo "-> Deleting of old tables"
mysql --user=root -e 'DROP DATABASE wikijob;'
@mrded
mrded / temperature_sensor.ino
Last active August 29, 2015 14:10
The LightBlue Bean: temperature sensor to make beer.
static int8_t t = 0;
void setup() {
// Initialize serial communication at 57600 bits per second:
Serial.begin(57600);
Bean.setLed(0, 0, 0);
}
void setLed(int8_t t, int fadeValue) {
if (t > 22) { // If greater than 22C, set LED to Red.
@mrded
mrded / range_of_dates.php
Last active August 29, 2015 14:06
PHP: Generate range of dates
<?php
function _date_range($first, $last, $step = '+1 day', $format = 'Y-m-d') {
$dates = array();
$current = strtotime($first);
$last = strtotime($last);
while ($current <= $last) {
$dates[] = date($format, $current);
$current = strtotime($step, $current);
@mrded
mrded / gist:9e11aea4ff0592de586b
Last active February 15, 2017 14:32
Drupal: Database Abstraction Layer
<?php
// SELECT One field: SELECT title FROM {node} WHERE nid = 123
$title = db_select('node', 'n')
->fields('n', array('title'))
->condition('n.nid', 123)
->execute()
->fetchField();
// SELECT One object: SELECT title FROM {node} WHERE nid = 123
@liamgriffiths
liamgriffiths / cors.md
Last active August 27, 2024 13:00
How CORS works

Guide to CORS

CORS (cross origin resource sharing) is a mechanism to allow client web applications make HTTP requests to other domains. For example if you load a site from http://domainA.com and want to make a request (via xhr or img src, etc) to http://domainB.com without using CORS your web browser will try to protect you by blocking the response from the other server. This is because browsers restrict responses coming from other domains via the Same-Origin-Policy.

CORS allows the browser to use reponses from other domains. This is done by including a Access-Control headers in the server responses telling the browser that requests it is making is OK and safe to use the response.

Header Description
Access-Control-Allow-Origin: Allow requests from `` to access t
@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, ...
@patrickhammond
patrickhammond / android_instructions.md
Last active July 22, 2025 02:25
Easily setup an Android development environment on a Mac

Here is a high level overview for what you need to do to get most of an Android environment setup and maintained.

Prerequisites (for Homebrew at a minimum, lots of other tools need these too):

  • XCode is installed (via the App Store)
  • XCode command line tools are installed (xcode-select --install will prompt up a dialog)
  • Java

Install Homebrew:

ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

@mrded
mrded / catch_error.js
Last active August 29, 2015 13:56
AngularJS: How to resolve promise objects.
function asynkFunction(){
return $timeout(function meAsynk(){
throw new Error('error in meAsynk');
}, 1);
}
asynkFunction().catch(function (err) {
errorHandler(err);
});
@malixsys
malixsys / app.scss
Last active July 11, 2016 07:42
ionic framework validation
form i.icon.error {
color: $assertive;
}
form input + i.icon.error {
display: none;
margin-left: 8px;
}
form.ng-submitted input.ng-invalid + i.icon.error {