Skip to content

Instantly share code, notes, and snippets.

View mpneuried's full-sized avatar
🏠
Working from home

M. Peter mpneuried

🏠
Working from home
View GitHub Profile
@mpneuried
mpneuried / pubsub.coffee
Last active December 10, 2015 23:28
Simple namespaced Pub/Sub coffee class to use as extendable module for NodeJS and the browser.
# # 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
@mpneuried
mpneuried / encode_decode_json_linebreak.coffee
Created January 28, 2013 15:35
encode json with linebreaks
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 February 11, 2013 08:51
Backbone code to move a model inside a collection after another model or to the top of the collection.
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 February 11, 2013 09:08
Multiple replace of keys inside a object or JSON. *Useful for replacing id's with new id's.*
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 February 14, 2013 15:05
Middleware solution to run multiple tasks
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
@mpneuried
mpneuried / spideroctocats.coffee
Created March 25, 2013 09:42
Spider all octocats
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 December 18, 2015 01:29
Workarround to store a clean array in mysql
# 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 December 18, 2015 21:39
Get the count of timestamps based on a given timeframe.
###
**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 July 9, 2018 08:27
bash helpers
# 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 July 27, 2016 13:11
SQL HELPERS :: SQL commands i allways have to search for
/* 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%';