Skip to content

Instantly share code, notes, and snippets.

View PatrickJS's full-sized avatar

PatrickJS PatrickJS

View GitHub Profile
@PatrickJS
PatrickJS / dabblet.css
Created June 12, 2014 20:05
Triangle with Shadow
/*
Triangle with Shadow
*/
input {
padding: 0;
margin: 0;
}
.form-control {
height: 34px;
padding: 6px 12px;
@PatrickJS
PatrickJS / dabblet.css
Created June 12, 2014 20:37
Triangle with Shadow
/*
Triangle with Shadow
*/
input {
padding: 0;
margin: 0;
outline: none;
-webkit-appearance: none;
}
input.origin:focus {
@PatrickJS
PatrickJS / dabblet.css
Created June 12, 2014 20:52
Triangle with Shadow
/*
Triangle with Shadow
*/
.pricing {
padding: 2em;
}
input {
padding: 0;
margin: 0;
@PatrickJS
PatrickJS / dabblet.css
Created June 12, 2014 21:49
Triangle with Shadow
/*
Triangle with Shadow
*/
.pricing {
padding: 2em;
}
.kcl-pricing {
display: inline-block;
@PatrickJS
PatrickJS / defineMethhod.js
Created June 22, 2014 19:01
Metaprogramming: Dynamic Method
Object.prototype.defineMethod = function(methodName, methodBody) {
Object.defineProperty(this, methodName, {
enumerable: true,
configurable: true,
value: methodBody
});
};
@PatrickJS
PatrickJS / pubnub-publish-channels.js
Last active August 29, 2015 14:03
Monkey patch multiple channel publishing
PUBNUB._publish = PUBNUB.publish;
PUBNUB.publish = function(body) {
var channels = body.channel;
if (typeof channels === 'string' && (/,/i).test(channels)) {
this.publish(channels.split(','));
}
if (Array.isArray(channels)) {
this.each(Array.prototype.slice.call(channels, 0), function(channel) {
body.channel = channel;
this.publish(body);
@PatrickJS
PatrickJS / number-zero-padding.js
Created June 28, 2014 03:44
padding number into string
Padding a string
Sometimes you want to pad numbers with zeros e.g. to align them on the console. Here is how I did that:
>>> ('00' + 3).slice(-3)
"003"
>>> ('00' + 42).slice(-3)
"042"
>>> ('00' + 103).slice(-3)
"103"
The -3 is the number*-1 of characters my string shall have in the end. I am adding two zeros at the beginning, because I am sure that a number is never an empty string. And after the string concatenation I just take only the last three characters. Simple but works nice without any kind of IFs or complex logic.
@PatrickJS
PatrickJS / google-maps-resolve.html
Last active August 29, 2015 14:03
If you are using the Google Maps API within your AngularJS app, then you probably know that it needs to be fully loaded before being used. That's why the Google API URL accepts a callback name to be called once is ready; the callback function have to be defined in the window context. You must delay the bootstraping of your app to ensure that the…
<script src="your/map.js"></script>
<script src="your/app.js"></script>
<script src="//maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&callback=onGoogleReady"></script>

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called (Functional) Reactive Programming (FRP).

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

@PatrickJS
PatrickJS / dynamic-next.js
Created June 30, 2014 22:26
dynamic next element
var dynamicNext = '2';
var nexts = _.range(+attrs.dynamicNext);
_.reduce(nexts, function(elm) {
return elm.next();
}, element)[0].focus();
// element.next().next()[0].focus();