Skip to content

Instantly share code, notes, and snippets.

var myScript = document.createElement('script');
myScript.src = 'http://code.jquery.com/jquery-2.1.4.min.js';
myScript.onload = function() {
console.log('jQuery loaded.');
};
document.body.appendChild(myScript);
function xdomain(par){//crossdomain function
par.xpath=par.xpath==undefined?"*":par.xpath;
par.type=par.type==undefined?"xml":par.type;
var xmlhttp=new XMLHttpRequest();
par.url = 'http://query.yahooapis.com/v1/public/yql?q='+encodeURIComponent('select * from html WHERE url="'+par.url+'" AND xpath="'+par.xpath+'"')+'&format='+par.type+'&callback=cb';
xmlhttp.open("GET",par.url,false);
xmlhttp.onload=function(){
function cb(d){return d;}//callBack function for returning results from query
par.callBack(eval(xmlhttp.responseText));
};
<?php
namespace App\Custom\Pagination\Presenters;
use Illuminate\Pagination\BootstrapThreePresenter;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\UrlWindow;
class MaterializePresenter extends BootstrapThreePresenter
{
module JSON2
# Extension to the ActiveModel::Serializers::JSON module
# An attributes=() method is provided that uses the same loop a custom-written method would but uses the
# value of the key in the 'attributes' hash to automatically handle contained objects:
# If the value from the 'attributes' hash is a string, symbol or class name and the value of the current
# key is a hash, the 'attributes' value is taken as the class the current attribute is supposed to be and
# the value hash will be passed to the new object's attributes=() method.
# As usual, a class can provide it's own attributes=() method if different handling is required.

Whether you use 2 spaces or 4 spaces, there are a few simple things that can make your node.js code easier to read. We've been using them in all the hapi modules for over 4 years now to great results. This list is by no means complete but it highlights the most useful elements that will give you immediate value in reducing bugs.

Required modules

JavaScript makes it harder than most languages to know where variables are coming from. Variables assigned required modules are particularly important because they represent a singleton object shared with the entire application. There are also globals and module globals, along with function variables and arguments.

Traditionally, variables starting with an uppercase letter represent a class that must be instantiated using new. This was an important semantic in the early days of JavaScript but at this point, if you don't know Date requires new Date() you are probably very new. We have adopted Upper Camel Case variable names for all module global variables

# -*- coding: utf-8 -*-
from django import template
from django.utils.encoding import force_unicode
from django.utils import timezone
from django.core.cache import cache
# import datetime
# from django.conf import settings
# from django.utils.formats import sanitize_separators
# from django.utils.html import conditional_escape as esc
var angular = require('angular');
// We can also make a TodoStore
var _todoState = {
todos: [
{ value:'finish example', created_at: new Date() },
{ value:'add tests', created_at: new Date() }
]
};
//
// SmoothScroll for websites v1.2.1
// Licensed under the terms of the MIT license.
//
// You may use it in your theme if you credit me.
// It is also free to use on any individual website.
//
// Exception:
// The only restriction would be not to publish any
// extension for browsers or native application
@janusnic
janusnic / bower.json
Last active August 29, 2015 14:21 — forked from Bersam/bower.json
{
"name": "bersam",
"homepage": "http://bersam.org",
"authors": [
"Bersam Karbasion <[email protected]>"
],
"license": "MIT",
"private": true,
"dependencies": {
"modernizr": "2.8.2",
@janusnic
janusnic / IEEE754.rb
Last active August 29, 2015 14:22 — forked from domgetter/IEEE754.rb
bits = eval("0x" + [0.15625].pack('g').unpack('H16')[0]).to_s(2).rjust(32,"0")
#=> "00111110001000000000000000000000"
# these are the bits of 0.15625 represented as a single precision float
sign = bits[0]
#=> "0"
exponent = bits[1..8]
#=> "01111100"
mantissa = bits[9..32]
#=> "01000000000000000000000"
sign = sign.to_i == 0 ? 1 : -1