Skip to content

Instantly share code, notes, and snippets.

@JSila
JSila / laravel-socialite.md
Last active August 29, 2015 14:16
How to: Laravel Socialite

In this case we want to authenticate with twitter. This gist assumes new twitter app is already generated (we need client id, client secret and redirect url).

First require the package with composer

composer require laravel/socialite:~2.0

Register service provider and facade for the package.

Then add credentials for authentication with twitter in config/services.php:

@JSila
JSila / BladeExtensionsProvider.php
Last active August 29, 2015 14:16
Few additional tags for blade templating engine
<?php namespace App\Providers;
use Illuminate\Support\ServiceProvider;
class BladeExtensionsProvider extends ServiceProvider {
// Don't forget to register this provider in config/app.php
//
// Or if you don't want to bother, add content of boot function
// to AppServiceProvider.php's boot function
@JSila
JSila / localStorage.js
Created June 26, 2015 22:33
this helps with saving and retriving values other than strings from localStorage.
Storage.prototype.getItem = function(key) {
try {
return JSON.parse(this[key]);
} catch (error) {}
return this[key];
}
Storage.prototype.setItem = function(key, value) {
this[key] = (typeof value == 'string') ? value : JSON.stringify(value);
}
@JSila
JSila / instruction.md
Last active October 3, 2015 14:55
Quick set-up for ES6 project with babel and browserify.

It's easy! There are only 2 steps:

  1. Install required packages with NPM: npm install browserify babelify

  2. Create package.json with the following content (here main.js file is source file and bundle.js is output file. Also note we are applying transformer to browserify command):

    {
      "scripts": {
        "build-js": "browserify -t babelify main.js > bundle.js"

}

@JSila
JSila / main.go
Created January 13, 2016 22:22
Basic Auth middleware with example of use
package main
import (
"fmt"
"net/http"
)
func BasicAuth(username string, password string) func(http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// I created Delete method on Post struct
func (p *Post) Delete(db *DB) error {
_, err := db.Exec("DELETE FROM posts WHERE id = ?", p.ID)
if err != nil {
return err
}
return nil
}
@JSila
JSila / eslint.json
Created March 17, 2016 23:58
eslint.js for React and ES6
{
"rules":{
"indent": 2,
"quotes": [2, "single"],
"linebreak-style": [2, "unix"],
"react/prop-types":1,
"react/no-multi-comp":1,
"no-unused-vars":2,
"no-undef":2
},
@JSila
JSila / restart
Last active April 7, 2016 12:07
Bash script for building and starting application written in Go. Also if some file is changed, it rebuilds and restarts application.
#!/bin/bash
# Bash script for building and starting application in Go. Also if some file is changed, it rebuilds and restarts application.
# Before running the script, inotify-tools has to be installed.
trap ctrl_c INT
function ctrl_c {
kill $PID
log "stopped"
@JSila
JSila / cool-js-libs.md
Last active April 7, 2016 13:35
JavaScript libraries that I discovered and deserves a special mention.
  • FlightJS: A component-based, event-driven JavaScript framework built on top of jQuery. From Twitter.
  • React: A declarative, efficient, and flexible JavaScript library for building user interfaces. Developed and used by Facebook and Instagram.
  • Redux: Predictable state container for JavaScript application.
  • stampit: Create objects from reusable, composable behaviors. Stampit uses three different kinds of prototypal OO to let you inherit behavior in a way that is much more powerful and flexible than classical OO.
  • unexpected-react: Extension for unexpected assertion library to make testing React components easier.
@JSila
JSila / clean-public.js
Last active April 14, 2016 21:44
gulpfile.js for developing applications in React with ES6
module.exports = (gulp, del, paths) => {
gulp.task('clean-public', () => {
return del([ paths.jsPublicFiles, paths.jsSourceMaps ]);
});
};