Skip to content

Instantly share code, notes, and snippets.

@EtienneR
EtienneR / user.js
Created January 7, 2016 23:39
XMLHttpRequest RESTful (GET, POST, PUT, DELETE)
// Get all users
var url = "http://localhost:8080/api/v1/users";
var xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.onload = function () {
var users = JSON.parse(xhr.responseText);
if (xhr.readyState == 4 && xhr.status == "200") {
console.table(users);
} else {
console.error(users);
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Countries CRUD</title>
<style>
input[type='submit'], button, [aria-label]{
cursor: pointer;
}
#spoiler{
@EtienneR
EtienneR / index.js
Created July 29, 2019 21:43
Very basic JWT Express login / register API (no database, no Bcrypt)
const express = require('express')
const morgan = require('morgan')
const jwt = require('jsonwebtoken')
const cors = require('cors')
const PORT = 1234
const SECRET = 'mykey'
const app = express()
app.use(cors())
package main
import (
"github.com/gin-gonic/gin"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
)
type Users struct {
Id int `gorm:"AUTO_INCREMENT" form:"id" json:"id"`
package main
import (
"database/sql"
"gopkg.in/gorp.v1"
"log"
"strconv"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
@EtienneR
EtienneR / filters.html
Created April 12, 2017 13:05
Petit TP sur les filtres en JavaScript
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Movies - Filter</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body class="container" style="margin-top: 1rem;">
@EtienneR
EtienneR / Gulpfile.js
Created March 17, 2016 14:56
Auto reload your Go webserver with Gulp
const gulp = require('gulp'),
util = require('gulp-util'),
notifier = require('node-notifier'),
sync = require('gulp-sync')(gulp).sync,
reload = require('gulp-livereload'),
child = require('child_process'),
os = require('os');
var server = null;
@EtienneR
EtienneR / pagination.go
Created June 29, 2017 21:42
Paginate an array and order by descending "id"
package main
import (
"fmt"
"math"
"sort"
)
type idSorter []article
@EtienneR
EtienneR / index.js
Created November 2, 2018 15:24
Very simple JWT server
// npm install express morgan jsonwebtoken cors
const express = require('express')
const morgan = require('morgan')
const jwt = require('jsonwebtoken')
const cors = require('cors')
const PORT = 1234
const SECRET = 'mykey'
const app = express()
'title': 'This is my go blog'
'email': 'go@email.com'
'tags': [go, golang, yaml, json]