Skip to content

Instantly share code, notes, and snippets.

@virolea
virolea / upload.js
Last active March 15, 2024 13:45
Tracking file upload progress using axios
upload(files) {
const config = {
onUploadProgress: function(progressEvent) {
var percentCompleted = Math.round((progressEvent.loaded * 100) / progressEvent.total)
console.log(percentCompleted)
}
}
let data = new FormData()
data.append('file', files[0])
@m1r0
m1r0 / wp_insert_attachment_from_url.php
Last active April 11, 2024 12:33
WP: Insert attachment from URL
<?php
/**
* Insert an attachment from a URL address.
*
* @param string $url The URL address.
* @param int|null $parent_post_id The parent post ID (Optional).
* @return int|false The attachment ID on success. False on failure.
*/
function wp_insert_attachment_from_url( $url, $parent_post_id = null ) {
@6174
6174 / Random-string
Created July 23, 2013 13:36
Generate a random string in JavaScript In a short and fast way!
//http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
@LarsWerkman
LarsWerkman / Main.java
Created February 11, 2013 13:53
A sample application which shows what the HoloColorPicker library can do.
public class Main extends Activity implements OnColorChangedListener {
private ColorPicker picker;
private SVBar svBar;
private OpacityBar opacityBar;
private Button button;
private TextView text;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ternarybit
ternarybit / time_delta.php
Created May 11, 2011 23:14
Express difference between two timestamps in various English time units
/*
time_delta() returns the difference between two times
expressed in many ways.
(mixed) $start: The initial time to calculate from
(mixed) $target: The time in the past or future to calculate the difference between
(int) $precision:
0: Generic - ex. "About 7 hours ago"
1: Approximate - ex. "7 hours, 15 minutes ago"
2: Exact - ex. "7 hours, 15 minutes and 6 seconds ago"
@bzerangue
bzerangue / yahoo-weather-condition-codes.xml
Created February 1, 2011 06:53
Yahoo Weather Condition Codes
<?xml version="1.0" encoding="UTF-8"?>
<yahoo-weather-codes>
<code number="0" description="tornado"/>
<code number="1" description="tropical storm"/>
<code number="2" description="hurricane"/>
<code number="3" description="severe thunderstorms"/>
<code number="4" description="thunderstorms"/>
<code number="5" description="mixed rain and snow"/>
<code number="6" description="mixed rain and sleet"/>
<code number="7" description="mixed snow and sleet"/>