Skip to content

Instantly share code, notes, and snippets.

function fitStringToSize(str,len) {
var result = str;
var span = document.createElement("span");
span.style.visibility = 'hidden';
span.style.padding = '0px';
document.body.appendChild(span);
// on first run, check if string fits into the length already.
span.innerHTML = result;
if(span.offsetWidth > len) {
@andyburke
andyburke / facebook-photo-post-javascript.js
Created December 19, 2011 20:37
How to post a photo to Facebook from client-side Javascript
// This bit is important. It detects/adds XMLHttpRequest.sendAsBinary. Without this
// you cannot send image data as part of a multipart/form-data encoded request from
// Javascript. This implementation depends on Uint8Array, so if the browser doesn't
// support either XMLHttpRequest.sendAsBinary or Uint8Array, then you will need to
// find yet another way to implement this. (This is left as an exercise for the reader,
// but if you do it, please let me know and I'll integrate it.)
// from: http://stackoverflow.com/a/5303242/945521
if ( XMLHttpRequest.prototype.sendAsBinary === undefined ) {
@bhubbard
bhubbard / .htaccess
Last active December 25, 2023 02:59
This is my template .htaccess file for WordPress on Cloud Sites.
# Apache Server Config | MIT License
# https://gist.github.com/bhubbard/6082577
# Modified from https://github.com/h5bp/server-configs-apaches
# ##############################################################################
# # Default WordPress #
# ##############################################################################
# http://randomtype.ca/blog/the-wordpress-htaccess-file-explained/
# BEGIN WordPress
@mxl
mxl / PageSplitter.java
Last active December 29, 2015 09:09
Class for splitting styled text to pages.
package com.codeoverdrive.util;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.TextPaint;
import android.text.style.StyleSpan;
import java.util.ArrayList;
import java.util.List;
<?php
$db = @mysql_connect('localhost', 'root', 'password') or die(mysql_error());
mysql_select_db('test', $db) or die(mysql_error());
$qry_qbank = mysql_query("SELECT * FROM at_qa_dump limit 100") or die(mysql_error());
//require('wp-blog-header.php');
while ($row = mysql_fetch_array($qry_qbank)) {
$qno = $row['ID'];
$question_title = $row['Question_Title'];
$question_content = $row['Question_Content'];
@lovasoa
lovasoa / README.md
Last active December 7, 2016 09:22
Download and assemble tiles of an image
@rkennesson
rkennesson / vmware.txt
Last active June 12, 2024 18:40
VMWare - hide the fact that you are running in a VM
#https://www.google.com/search?q=smbios.reflecthost&oq=smbios.r&aqs=chrome.0.0j69i57j0l4.2850j0j7&sourceid=chrome&ie=UTF-8 | smbios.reflecthost - Google Search
#http://www.bitcon.be/how-to-install-an-hp-branded-windows-os-as-a-virtual-server/ | How to install an HP branded Windows OS as a virtual server | BITCON - IT consultants
#https://communities.vmware.com/thread/162241?tstart=0 | This system is not supported platform |VMware Communities
#https://superuser.com/questions/199906/how-to-edit-bios-information-for-a-virtual-machine-in-vmware | How to edit BIOS information for a virtual machine in VMWare? - Super User
#http://www.insanelymac.com/forum/topic/292170-how-to-spoof-real-mac-in-vmware/ | How to spoof real Mac in VMware - Multi-booting and Virtualisation - InsanelyMac Forum
Method 1: edit VMX file for the specific VM
#add this line
SMBIOS.reflectHost = TRUE
<?php
/**
* Check the orderby param for the particular REST API for hte custom post type.
* If it is set to a particular meta_ket, then set the orderby and meta_key query args/
* @link https://www.timrosswebdevelopment.com/wordpress-rest-api-order-by-meta_value/
*/
function filter_rest_accommodation_query($query_vars, $request) {
$orderby = $request->get_param('orderby');
if (isset($orderby) && $orderby === 'number_of_beds') {
$query_vars["orderby"] = "meta_value_num";
@aaronsummers
aaronsummers / Adding-meta-fields-with-orderby-endpoint-to-WordPress-rest_API.php
Created December 6, 2019 13:36
Adding meta fields with orderby endpoint to WordPress rest API
<?php
// Register the meta field for the rest api
// https://stackoverflow.com/questions/56460557/how-to-include-meta-fields-in-wordpress-api-post#answer-56508996
add_action( 'rest_api_init', 'register_postviews_meta_fields');
function register_postviews_meta_fields(){
register_meta( 'post', 'wpb_post_views_count', array(
'type' => 'integer',
'description' => 'Post views',
'single' => true,
import xml.etree.ElementTree as ET
import glob
import os
import json
def xml_to_yolo_bbox(bbox, w, h):
# xmin, ymin, xmax, ymax
x_center = ((bbox[2] + bbox[0]) / 2) / w
y_center = ((bbox[3] + bbox[1]) / 2) / h