Skip to content

Instantly share code, notes, and snippets.

@luogaara
luogaara / chatglm-openai-api.ipynb
Created April 21, 2023 07:36 — forked from ninehills/chatglm-openai-api.ipynb
chatglm-openai-api.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
function qSort(compare) {
var swap = (p1, p2) => {
var tmp = this[p1];
this[p1] = this[p2];
this[p2] = tmp;
}
var sortRange = (start, end) => {
var midValue = this[start];
var p1 = start, p2 = end - 1;
while(p1 < p2) {
@luogaara
luogaara / extend.js
Created September 9, 2016 06:44 — forked from cferdinandi/extend.js
A native JS extend() function.
/**
* Merge defaults with user options
* @private
* @param {Object} defaults Default settings
* @param {Object} options User options
* @returns {Object} Merged values of defaults and options
*/
var extend = function ( defaults, options ) {
var extended = {};
var prop;
@luogaara
luogaara / Change Tag name.js
Created April 14, 2016 07:36
Change tag name while preserving attributes - (Requires jQuery)
var change_tag_name = function(selector,tagname){
var old_elm = $(selector);
//Create a jquery element based on selector
var original_elements = old_elm.get();
//Get the array of original dom objects
//Note: We get the original dom objects because jQuery objects do not provide access to the attributes array
for(var i=0; i< original_elements.length; i+=1){
var original_element = original_elements[i];
//Create reference to original element in dom
var new_elm = $(document.createElement(tagname));
@luogaara
luogaara / description.md
Created December 1, 2015 06:12 — forked from Integralist/description.md
Detect previousElementSibling/nextElementSibling

Description

My team likes to use the previousElementSibling and nextElementSibling methods as it saves them having to filter out TEXT_NODES (which the majority of the time - when sifting through the DOM - they don't have to worry about).

Internet Explorer <= 8 doesn't support either method, but it's current DOM implementation ignores TEXT_NODES (when using previousSibling and nextSibling) so they already act like previousElementSibling and nextElementSibling.

But when checking over my teams code I noticed that they would use a conditional code branching in every instance where they wanted to use previousElementSibling and nextElementSibling, so to try and help keep their code DRY I just used a very basic feature detection script to abstract these methods into two separate functions for them to use instead.

Caveat

@luogaara
luogaara / slider-2.js
Created October 15, 2015 13:37 — forked from Xeodee/slider-2.js
Slider
var clicked = false,
i = -1,
y = $(".contentContainer").length,
y2 = y+2,
z = y-1;
$(".sliderHolder").css("width", $(window).width());
$(".contentContainer").css("width", $(window).width());
$(".homeSlider").css("width", $(window).width()*y2);
$('.contentContainer').eq(1).clone().appendTo('.homeSlider');
$('.contentContainer').eq(y-1).clone().prependTo('.homeSlider');
@luogaara
luogaara / example-wp-list-table.php
Created September 30, 2015 16:08 — forked from paulund/example-wp-list-table.php
An example code of using the WP_List_Table class. With Pagination.
<?php
/*
* Plugin Name: Paulund WP List Table Example
* Description: An example of how to use the WP_List_Table class to display data in your WordPress Admin area
* Plugin URI: http://www.paulund.co.uk
* Author: Paul Underwood
* Author URI: http://www.paulund.co.uk
* Version: 1.0
* License: GPL2
*/