Skip to content

Instantly share code, notes, and snippets.

View DennisRas's full-sized avatar
💪
Let's do this !

Dennis Rasmussen DennisRas

💪
Let's do this !
View GitHub Profile
@DennisRas
DennisRas / star.svg
Created April 7, 2018 09:05
SVG with a star and a number ontop
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@DennisRas
DennisRas / app.js
Created March 18, 2018 21:09
Express route-specific JSON response
var express = require('express')
var bodyParser = require('body-parser')
var app = express()
// create application/json parser
var jsonParser = bodyParser.json()
app.post('/api/users', jsonParser, function (req, res) {
if (!req.body) return res.sendStatus(400)
res.json({foo: 'bar'})
});
@DennisRas
DennisRas / config.php
Created November 5, 2011 20:44
Autoloader for CodeIgniter
function __autoload($class)
{
if (strpos($class, 'CI_') !== 0)
{
if (file_exists($file = APPPATH . 'core/' . $class . EXT))
{
include $file;
}
elseif (file_exists($file = APPPATH . 'libraries/' . $class . EXT))
{
@DennisRas
DennisRas / gist:1313736
Created October 25, 2011 18:23
Convert assoc values from alpha to numeric position of the alhapbet
<?php
$array = array('hi' => 'a', 'yo' => 'b');
array_walk($array, function(&$value, $key){
$value = strpos('abcdefghijklmnopqrstuvwxyz', $value) + 1;
});
print_r($array); // Array ( [hi] => 1 [yo] => 2 )
// < PHP 5.3
function alphanum(&$value, $key){
<snippet>
<content><![CDATA[
<div class="clearfix">
<label for="$1">$2</label>
<div class="input">
<?=form_input('$1', set_value('$1'), 'id="$1"')?>
</div>
</div>
]]></content>
<tabTrigger>formtext</tabTrigger>
@DennisRas
DennisRas / .htaccess
Created August 26, 2011 14:32
CodeIgniter .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
@DennisRas
DennisRas / time_ago.php
Created August 26, 2011 14:24
My suggestion for a time function
<?php
if ( ! function_exists('time_ago'))
{
function time_ago($time, $max_units = NULL)
{
$lengths = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
$units = array('second', 'minute', 'hour', 'day', 'week', 'month', 'year', 'decade');
$unit_string_array = array();
@DennisRas
DennisRas / server.js
Created August 16, 2011 21:03
Doesn't work with node.exe
var mysql = require('mysql');
var client = mysql.createClient({
user: 'dennisrasmussen',
password: '****************',
host: '*****************',
database: 'dennisrasmussen',
port: 9000
});
@DennisRas
DennisRas / npm-debug.log
Created August 16, 2011 12:36
Error installing NPM with Cygwin
info it worked if it ends with ok
verbose cli [ 'node',
verbose cli '/home/Dennis/npm/cli.js',
verbose cli 'install',
verbose cli '-g',
verbose cli '-f' ]
info using npm@1.0.25
info using node@v0.5.5-pre
verbose config file /home/Dennis/.npmrc
verbose config file /usr/local/etc/npmrc