Skip to content

Instantly share code, notes, and snippets.

View tcdevs's full-sized avatar

TC Devs tcdevs

  • Technische Centrale
View GitHub Profile
@mikelehen
mikelehen / generate-pushid.js
Created February 11, 2015 17:34
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/
@asyncanup
asyncanup / simple-javascript-assert.md
Last active May 11, 2022 01:03
Simple JavaScript assert

Why you need assertions

It's better to fail with your own error than undefined is not a function.

A simple assertion solution would let your application fail early and fail at the right point in runtime execution. Allowing you to handle it better.

How you write assertions

@LulzAugusto
LulzAugusto / sitef-date.js
Last active August 29, 2015 14:03
A simple date handler that does the job while we don't need something complex as Moment.js
/*=====================================================
*
* Sitef Date : A javascript library that handles dates in a way that fits Sitef's needs
* (c) Luiz Augusto Crisostomo 2014
*
======================================================*/
function SitefDate(date) {
@justinmc
justinmc / anchor_smooth_scroll.js
Last active May 14, 2019 19:52
Anchor Smooth Scroll - Angular Directive
/**~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* Anchor Smooth Scroll - Smooth scroll to the given anchor on click
* adapted from this stackoverflow answer: http://stackoverflow.com/a/21918502/257494
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
angular.module('yourapp').directive('anchorSmoothScroll', function($location) {
'use strict';
return {
restrict: 'A',
replace: false,
@esfand
esfand / angular-jqlite.adoc
Last active April 19, 2023 01:32
Angular jqLite

Angular jqLite

jQuery and Angular

Angular doesn’t depend on jQuery. In fact, the Angular source contains an embedded lightweight alternative: jqLite. Still, when Angular detects the presence of a jQuery version in your page, it uses that full jQuery implementation in lieu of jqLite. One direct way in which this manifests itself is with Angular’s element abstraction. For example, in a directive you get access to the element that the directive applies to:

@iotaweb
iotaweb / gist:8228261
Last active January 2, 2016 01:09
md5 factory for AngularJS
/*
* http://kevin.vanzonneveld.net
* original by: Webtoolkit.info (http://www.webtoolkit.info/)
* namespaced by: Michael White (http://getsprink.com)
* tweaked by: Jack
* improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
* input by: Brett Zamir (http://brett-zamir.me)
* bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
* depends on: utf8_encode
* example 1: md5('Kevin van Zonneveld');
var uuids = angular.module('uuids', []);
uuids.factory("rfc4122", function () {
return {
newuuid: function () {
// http://www.ietf.org/rfc/rfc4122.txt
var s = [];
var hexDigits = "0123456789abcdef";
for (var i = 0; i < 36; i++) {
s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
}
@es
es / functional.js
Created December 8, 2013 20:55
Implementation of Curry, Uncurry, & Compose functions (with accompanying tests).
/*
* Curry takes a two argumented function and returns one func that returns a second func that each take one argument.
*/
function curry (func) {
return function (x) {
return function (y) {
return func (x, y);
};
};
@BFTrick
BFTrick / remove-nf-required-fields-string.php
Created November 5, 2013 22:18
Remove the Ninja Forms required fields string above a form with 1+ required strings.
<?php
/**
* Change text strings
*
* @link http://codex.wordpress.org/Plugin_API/Filter_Reference/gettext
*/
function my_nf_required_fields_strings( $translated_text, $text, $domain ) {
switch ( $translated_text ) {
case 'Fields marked with a * are required' :
$translated_text = __( '', 'ninja-forms' );
@CMCDragonkai
CMCDragonkai / angularjs_directive_attribute_explanation.md
Last active November 29, 2023 15:35
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>