Skip to content

Instantly share code, notes, and snippets.

View icharge's full-sized avatar

Norrapat Nimmanee icharge

View GitHub Profile
@juliocesar
juliocesar / best-localStorage-polyfill-evar.js
Created April 18, 2011 23:19
This is the best localStorage polyfill in the world
// I mean, seriously, localStorage is supported even by your mum. How about instead of
// casing the feature out, you give users in-memory (stale) storage instead?
// If they close your application, they deserve to lose data anyway.
// if (!('localStorage' in window)) {
if (!Modernizr.localstorage) {
window.localStorage = {
_data : {},
setItem : function(id, val) { return this._data[id] = String(val); },
getItem : function(id) { return this._data.hasOwnProperty(id) ? this._data[id] : undefined; },
@guybrush
guybrush / gist:2964418
Created June 21, 2012 07:40
dnode reconnect
var dnode = require('dnode')
var net = require('net')
var port = 3000
connect()
setTimeout(listen,1000)
function connect() {
console.log('connecting')
var netClient = net.connect(port)
@sukharevd
sukharevd / wildfly-install.sh
Last active October 21, 2023 11:56
Script to install JBoss Wildfly 10.x as service in Linux
#!/bin/bash
#title :wildfly-install.sh
#description :The script to install Wildfly 10.x
#more :http://sukharevd.net/wildfly-8-installation.html
#author :Dmitriy Sukharev
#date :2016-06-18T02:45-0700
#usage :/bin/bash wildfly-install.sh
#tested-version1 :10.0.0.CR3
#tested-distros1 :Ubuntu 15.10; Debian 7,8; CentOS 7; Fedora 22
#tested-version2 :10.0.0.Final
@clouddueling
clouddueling / MainCtrl.js
Last active November 3, 2022 13:26
How to authenticate using AngularJS
controllers.controller('MainCtrl', function($scope, $location, Facebook, $rootScope, $http, $location, Upload, Auth, User, Question, Category, Serie, Record, Location, Popup, Process, Card, Question) {
$scope.$on('authLoaded', function() {
$scope.isExpert($scope.main.serieId);
$scope.isMember($scope.main.serieId);
});
$scope.loadAuth = function() {
Auth.load().success(function(data) {
$scope.main.user = data.user;
$scope.$broadcast("authLoaded");
@kerimdzhanov
kerimdzhanov / random.js
Last active April 20, 2024 03:21
JavaScript: get a random number from a specific range
/**
* Get a random floating point number between `min` and `max`.
*
* @param {number} min - min number
* @param {number} max - max number
* @return {number} a random floating point number
*/
function getRandomFloat(min, max) {
return Math.random() * (max - min) + min;
}
@yangzhe1991
yangzhe1991 / example.java
Created April 10, 2014 06:50
example code of QueryBuilder in Cassandra Java driver
Session session = getSession();
//update
Statement exampleQuery = QueryBuilder.update("keyspace","table").with(QueryBuilder.set("height", 180))
.and(QueryBuilder.set("width", 300)).where(QueryBuilder.eq("id", 5145924587302797538L));
session.execute(exampleQuery);
//insert
exampleQuery= QueryBuilder.insertInto("keyspace","table").value("id",12245L)
.value("data",ByteBuffer.wrap(new byte[]{0x11})).ifNotExists();
@narate
narate / archey
Last active March 16, 2019 16:34
My archey OS X script. I'm not sure where this code came from. I install it via brew and then I edit via $ vim $(which archey)
#!/bin/bash
# System Variables
user=$(whoami)
hostname=$(hostname | sed 's/.local//g')
distro="OS X $(sw_vers -productVersion)"
kernel=$(uname)
uptime=$(uptime | sed 's/.*up \([^,]*\), .*/\1/')
shell="$SHELL"
terminal="$TERM"
// Slightly modified Adalight protocol implementation that uses FastLED
// library (http://fastled.io) for driving WS2811/WS2812 led stripe
// Was tested only with Prismatik software from Lightpack project
#include "FastLED.h"
#define NUM_LEDS 114 // Max LED count
#define LED_PIN 6 // arduino output pin
#define GROUND_PIN 10
#define BRIGHTNESS 255 // maximum brightness
@youssman
youssman / regex-camelCase-to-dash.js
Created November 5, 2014 11:19
Javascript convert camelcase to dash (hyphen)
function camelCaseToDash( myStr ) {
return myStr.replace( /([a-z])([A-Z])/g, '$1-$2' ).toLowerCase();
}
var myStr = camelCaseToDash( 'thisString' );
alert( myStr ); // => this-string
@brunocribeiro
brunocribeiro / SendEmailOffice365.java
Created June 2, 2015 00:05
JavaMail samples using Office365 SMTP
import java.util.Date;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.mail.Authenticator;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;