Skip to content

Instantly share code, notes, and snippets.

@yuheiy
yuheiy / shuffle.js
Last active August 29, 2015 14:27
shuffle arranges in javascript. Fisher-Yates.
function shuffle(list) {
var i = list.length;
while (--i) {
var j = Math.floor(Math.random() * (i + 1));
if (i == j) continue;
var k = list[i];
list[i] = list[j];
list[j] = k;
}
import React from 'react';
import dynamics from 'dynamics.js';
class Box extends React.Component {
constructor(props) {
super(props);
this.state = {
x: 0,
y: 0
};
var users = [
{ name: 'tom', age: 18 },
{ name: 'bob', age: 24 },
{ name: 'john', age: 36 }
];
<dl>
<dt>name</dt>
<dd>tom</dd>
<dt>age</dt>
<dd>18</dd>
</dl>
<dl>
<dt>name</dt>
<dd>bob</dd>
var frag = document.createDocumentFragment();
for (var i = 0, l = users.length; i < l; i++) {
var user = users[i];
var dl = document.createElement('dl');
var nameTerm = document.createElement('dt');
nameTerm.textContent = 'name';
dl.appendChild(nameTerm);
var html = users.map(function (user) {
return `
<dl>
<dt>name</dt>
<dd>${user.name}</dd>
<dt>age</dt>
<dd>${user.age}</dd>
</dl>
`;
});
var empty = function (el) {
while (el.firstChild) {
el.removeChild(el.firstChild);
}
};
var container = document.getElementById('container');
empty(container);
$(function () {
var $field = $('#field');
var $btn = $('#btn');
var $list = $('#list');
var addItem = function () {
var text = $field.val();
$list.append('<li>' + text + '</li>');
$field.val('');
};
<?php
pathinfo($filename, PATHINFO_EXTENSION);
<?php
$finfo = new finfo(FILEINFO_MIME_TYPE);
$finfo->file($filepath);