Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

M. Peter mpneuried

🏠
Working from home
View GitHub Profile
@mpneuried
mpneuried / pubsub.coffee
Last active Dec 10, 2015
Simple namespaced Pub/Sub coffee class to use as extendable module for NodeJS and the browser.
View pubsub.coffee
# # PubSub
#
# Is a small helper to simply realize a pub/sub pattern to a coffee class.
#
# A namespaceing of the topics is also included.
# This means you can subscribe to `a` and also get the `a.b`. But if you subscribe to `a.b` you will not get a `a`.
#
# **required module**: `underscore`
#
class PubSub
View encode_decode_json_linebreak.coffee
o = {
"ID": "BgQfL",
"jsonSettings": "{\"weight\":49,\"height\":158,\"heartrate_max\":168,\"phonebusiness\":\"03423/667840\",\"usergroups\":\"Mitglied\",\"colors\":{\"plantargets\":[],\"usergroups\":[],\"pain\":[],\"damage\":[],\"activeplan_targets\":[]},\"comment\":\"Skoliose\r\n\r\nPatientin ist hypermobil\r\n\r\nbd Clavicula gebrochen; links 2011, recht 1997\",\"plantargets\":\"Muskelaufbau,Ausdauer\"}",
"firstname": "Heike",
"lastname": "Jüttner"
}
console.log( o.jsonSettings )
_json =
encode: ( s )->
@mpneuried
mpneuried / backbone_moveafter.coffee
Created Feb 11, 2013
Backbone code to move a model inside a collection after another model or to the top of the collection.
View backbone_moveafter.coffee
class SortableCollection extends Collection
###
## moveAfter
`collections.moveAfter( model, predecessor )`
Move a model after another model or if `predecessor` is `null` or `0` to the top of the model list
@param { Model | String | Number } model The model to move, it's `id` or the `cid`
@mpneuried
mpneuried / jsonreplace.coffee
Created Feb 11, 2013
Multiple replace of keys inside a object or JSON. *Useful for replacing id's with new id's.*
View jsonreplace.coffee
class JSONreplace
###
## _jsonreplacemap
`_jsonreplacemap( _json, map )`
Replace the values of a key inside of a json string.
@param { String | Object } _json A Stringfied JSON or a object witch will be stringfied.
@mpneuried
mpneuried / middleware.coffee
Created Feb 14, 2013
Middleware solution to run multiple tasks
View middleware.coffee
class Middleware
constructor: ->
# define a shared object witch will be routed through all called methods
shared = {}
# run the middleware method to process all defined methods
# If one method fails by calling error the queue will be stopped
@middleware shared, @simpleCall, @addSomeMethods, ( err, shared )=>
if err
View spideroctocats.coffee
fs = require( "fs" )
request = require( "request" )
async = require( "async" )
### call this in the octocats list:
list = []
$( "img" ).each ( i, el )->
#console.log arguments
_src = $( @ ).data( "src" )
@mpneuried
mpneuried / clean_array.sql
Last active Dec 18, 2015
Workarround to store a clean array in mysql
View clean_array.sql
# drop a existing test table
DROP TABLE IF EXISTS `test`;
# create the test table
CREATE TABLE `test` (
`_h` varchar(5) NOT NULL DEFAULT '',
`_set` text,
PRIMARY KEY (`_h`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
@mpneuried
mpneuried / timeCountBy.coffee
Last active Dec 18, 2015
Get the count of timestamps based on a given timeframe.
View timeCountBy.coffee
###
**IMPORTANT** Make shure moment.js is available.
**ARGUMENTS**
* `timestamps` *( Array )*:An arry of timestamps.
* `type` *( String )*: A moment time type like `minute`, `hour`, `day`
* `pastCursor` *( Number )*: A number to define the maximum time to the past. If lower than `0` all given timestamps will be returned.
###
@mpneuried
mpneuried / cron.sh
Last active Jul 9, 2018
bash helpers
View cron.sh
# CRON: crontab header to run node and grunt within a cron job
#!/bin/sh
SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
@mpneuried
mpneuried / helpers.sql
Last active Jul 27, 2016
SQL HELPERS :: SQL commands i allways have to search for
View helpers.sql
/* activate global logging and the logfile path*/
SET GLOBAL general_log = 'ON';
SET GLOBAL general_log_file = '/Users/mathiaspeter/logs/mysql_general.log';
/* deactivate global logging */
SET GLOBAL general_log = 'OFF';
/* show variables */
SHOW GLOBAL VARIABLES like '%log%';