working on it ...

Filters

Explore Public Snippets

Sort by

Found 15k snippets matching: store

    public by sTiLL-iLL  307860  0  5  14

    my nonblocking, threadsafe file writer/appender for nodejs. works great with clustered servers, and child processes that write to shared or static file-stores

    my nonblocking, threadsafe file writer/appender for nodejs. works great with clustered servers, and child processes that write to shared or static file-stores: scribbles.js
    // scribbles.js a nonblocking, threadsafe file writer/appender for nodejs
    
    var fs = require('fs'),
    	pth = require('path'),
    	cueMngr = {};
    
    function Scribbles(fileNm) {
    	this.handle = fileNm;
    	this.canWrite = false;
    	this.actionsRoster = [];
    };
    
    var scribbles = Scribbles.prototype;
    
    scribbles.action = function (err, dta, actionCue) {
    	if (err) {
    		throw err;
    	}
    	return actionCue();
    }
    
    scribbles.assign = function (func) {
    	this.action = func;
    	return this;
    }
    
    scribbles.scribble = function (dta, func) {
    	if (this.canWrite) {
    		this.actionCue = dta;
    		if (func) {
    			this.actionsRoster.push(func);
    		}
    	} 
    	else {
    		this.canWrite = true;
    		var slf = this,
    			taskProxy = {};
    		fs.appendFile(this.handle, dta, function (err) {
    			function actionCue() {
    				slf.canWrite = false;
    				if (slf.actionCue) {
    					var dta = slf.actionCue;
    					slf.scribble(dta);
    					slf.actionCue = null;
    				}
    			}
    			slf.action(err, dta, actionCue);
    			while (taskProxy = slf.actionsRoster.shift()) {
    				return taskProxy(err);
    			}
    			if (func) {
    				return func(err);
    			}
    		});
    	}
    	return this;
    };
    
    module.exports = function (fil) {
    	var nm = pth.resolve(fil);
    	return (cueMngr[nm] = cueMngr[nm] || new Scribbles(fil));
    }
    
    

    public by mporru @ Amazon_AWS_PHP_API  320859  0  5  0

    Amazon AWS - PHP: Generate signed expiring download URL

    This snippet demonstrates how to generate a download URL for a file stored in your S3 Bucket. This will work for all files, even ACL private files. Download URL will be active for the specified time. In order to use this service you must enable Amazon Simple Storage Service (Amazon S3) in your account.
    <?php
    require_once('sdk.class.php');
    $s3 = new AmazonS3();
    
    $fileName = 'test1.txt';
    $bucketName = 'myBucketName';
    
    $url = $s3->get_object_url($bucketName, $fileName, '1 hour');
    
    echo("Download url: <a href=\"$url\">$url</a>\n");
    ?>

    public by zer00ne  230363  1  6  1

    DB(store, schema) | Store Data in localStorage

    [FORK][ https://www.snip2code.com/Snippet/217248/object-data-store-----stuff-it-in-yer-cl
      // Local Data
       
    function DB(store, schema) {
          this.store = store;
          if (!localStorage[store] || typeof localStorage[store] == 'undefined') {
              localStorage[store] = JSON.stringify(schema|| {});
          }
          this.setData = function (key, val) {
              var lda = JSON.parse(localStorage[this.store]);
              doUpdate(ldta, key, val);
              localStorage[store] = JSON.stringify(ldta);
          };
          this.getData = function (key) {
              var ldta = JSON.parse(localStorage[this.store]);
              if (key) {
                  return pathGet(ldta, key);
              }
              return ldta;
          };
          this.reset = function (schema) {
              localStorage[this.store] = JSON.stringify(schema || {});
          };
          this.delete = function() {
              localStorage.removeItem(this.store);
          };
          var doUpdate = function (ob, kStr, val) {
              var kpth = keyStr.split('.'),
              i = 0, lstIdx = kpth.length - 1;
              for (;i < lstIdx; ++i) {
                  var key = kpth[i];
                  if (!(key in ob)) {
                      ob[key] = {};
                  }
                  ob = ob[key];
              }
              ob[kpth[lstIdx]] = val;
          };
          var pathGet = function (obj, key, leftOvrs) {
              if ( leftOvrs === undefined ) {
                  leftOvrs = key.split('.');
              }
              var cur = leftOvrs.shift();
              if ( typeof(obj) == 'object' && obj[cur] !== undefined ) {
                  if ( leftOvrs.length === 0 ) {
                      return obj[cur];
                  }
                  else if ( typeof(obj[cur]) == 'object' ) {
                      return arguments.callee(obj[cur], undefined, leftOvrs);
                  }
              }
              return null;
          };
      }
                            

    public by mtbauer  193685  0  4  0

    Store surplus item boilerplate

    All defects are cosmetic only in nature, and do not affect equipment performance.

    public by skaggej  237856  1  6  0

    SharePoint 2010 - Bulk Upload Solution Packages

    When migrating a SharePoint environment from 2007 to 2010, don't forget about your solution packages! You can extract them from the SharePoint 2007 Solution Store, then use this script to upload them all to SharePoint 2010 in seconds!
    $solutions = Get-ChildItem -Path "C:\downloads\Exported Solution Packages"
    $solutions | ForEach-Object {add-spsolution -literalpath "C:\Exported Solution Packages\$_"}

    public by cghersi  105430  651  11  10

    Java: read from USB using RXTX library

    This is a well-tested class to read from USB device using RXTX library. First of all place rxtxSerial.so (or rxtxSerial.dll) in the classpath. The received bytes are stored in a queue called "receivedBytes". This queue is filled by the serialEvent() callback called by RXTX framework. Users of this class should retrieve the ready data from "receiv
    import gnu.io.*;
    import java.io.*;
    
    import java.util.Enumeration;
    import java.io.IOException;
    
    /**
     * This class provides the utilities to read the data exchanged via USB port.
     */
    public class USBComm implements SerialPortEventListener {
    
    	/**
    	 * Stream for the storage of incoming data
    	 */
    	private InputStream inputStream;
    	/**
    	 * Stream for the dispatching of data
    	 */
    	private OutputStream outputStream;
    	/**
    	 * Timeout of the USB port
    	 */
    	private final int PORT_TIMEOUT = 2000;
    	/**
    	 * Representation of the serial port used for the communication
    	 */
    	private SerialPort serialPort;
    	/**
    	 * Buffer that stores the received bytes from the media
    	 */
    	protected LinkedBlockingQueue<Byte> receivedBytes;
    
    	/**
    	 * Builds a new manager for the communication via USB port.
    	 * @exception IOException if an error occurred during the opening of the USB port
    	 */
    	public USBComm() throws IOException {
    	  receivedBytes = new LinkedBlockingQueue<Byte>(100000);
    		String port = "COM1"; //place the right COM port here, OS dependent
    	
    		//Check that the USB port exists and is recognized:
    		Enumeration<?> portList = CommPortIdentifier.getPortIdentifiers();
    		boolean portFound = false;
    		CommPortIdentifier portId = null;
    		while (portList.hasMoreElements()) {
    			portId = (CommPortIdentifier) portList.nextElement();
    		    if (portId.getPortType() == CommPortIdentifier.PORT_SERIAL) {
    		    	System.out.println.info(portId.getName());
    				if (portId.getName().equals(port)) {
    					System.out.println("Found port: " + port);
    				    portFound = true;
    				    break;
    				} 
    		    } 
    		} 
    	
    		if (!portFound) 
    		    throw new IOException("port " + port + " not found.");
    	
    		try {
    			System.out.println("USB port opening...");
    		    serialPort = (SerialPort) portId.open("USBCommunicator", PORT_TIMEOUT);
    		    System.out.println("USB port opened");
    		    inputStream = serialPort.getInputStream();
    		    outputStream = serialPort.getOutputStream();
    		    serialPort.addEventListener(this);
    			    	serialPort.notifyOnDataAvailable(true);
    			//#==================================================================#
    			// WARNING! - DO NOT SET THE FOLLOWING PROPERTY WITH RXTX LIBRARY, IT
    			// 			  CAUSES A PROGRAM LOCK:
    			// 	serialPort.notifyOnOutputEmpty(true);
    			//#==================================================================#
    			    	
    		    //wait for a while to leave the time to javax.comm to
    		    //correctly configure the port:
    		    Thread.sleep(1000);
    		    
    			int baudRate = 115200; //set propertly
    	    	serialPort.setSerialPortParams(baudRate, 
    	    		SerialPort.DATABITS_8, 
    	    		SerialPort.STOPBITS_1, 
    				SerialPort.PARITY_NONE);
    		    
    	    	serialPort.setFlowControlMode(SerialPort.FLOWCONTROL_NONE);
    	    		
    		    System.out.println("setted SerialPortParams");
    		} catch (Exception e) {
    			System.err.println(e.getMessage());
    			throw new IOException(e.getMessage());
    		}
    	}
    
    	
    	public void closeUSB(){
    		//close the streams for serial port:
    		try {
    			inputStream.close();
    			outputStream.close();
    		} catch (IOException e) {
    			System.err.println("Cannot close streams:" + e.getMessage(), e);
    		}
    	}
    
    	/**
    	 * Listener for USB events
    	 * 
    	 * @param event new event occurred on the USB port
    	 */
    	public void serialEvent(SerialPortEvent event){
    		switch (event.getEventType()) {
    	
    			case SerialPortEvent.BI:
    			case SerialPortEvent.OE:
    			case SerialPortEvent.FE:
    			case SerialPortEvent.PE:
    			case SerialPortEvent.CD:
    			case SerialPortEvent.CTS:
    			case SerialPortEvent.DSR:
    			case SerialPortEvent.RI:
    			case SerialPortEvent.OUTPUT_BUFFER_EMPTY:
    				//nothing to do...
    			    break;
    	
    			case SerialPortEvent.DATA_AVAILABLE:
    				byte received = -1;
    				do {
    					try {
    						received = (byte)inputStream.read();
    					} catch (IOException e) {
    						System.err.println("Error reading USB:" + e.getMessage());
    					}
    				
    					synchronized (receivedBytes) {
    						try {
    							receivedBytes.add(received);
    						} catch (IllegalStateException ew) {
    							System.err.println(ew.getMessage());
    							receivedBytes.poll();
    							receivedBytes.add(received);
    						}
    					}
    				} while(received != -1);
    
    			    break;
    		}
    	}
    
    	protected void write(byte[] buffer){
    	    try {
    	    	outputStream.write(buffer);
    	    	outputStream.flush();
    	    } catch (IOException e) {
    	    	System.err.println("Cannot write:" + e.getMessage());
    	    }
    	}
    }            

    public by christopher  169662  0  4  0

    Copied from my local repo (Not pushed fully to a branch on github itself.) For preview purpose for a friend. Just a standard BlockStateUtil that is going to be used to compare block states for restoration.. This is very basic. To remove the bk...

    Copied from my local repo (Not pushed fully to a branch on github itself.) For preview purpose for a friend. Just a standard BlockStateUtil that is going to be used to compare block states for restoration.. This is very basic. To remove the bkcommonlib dependency remove the blockStatesMatch function.. The Pair is nothing but a class wit
    package com.noxpvp.core.utils;
    
    import java.util.logging.Level;
    
    import org.bukkit.block.Beacon;
    import org.bukkit.block.BlockState;
    import org.bukkit.block.BrewingStand;
    import org.bukkit.block.Chest;
    import org.bukkit.block.CommandBlock;
    import org.bukkit.block.CreatureSpawner;
    import org.bukkit.block.Dispenser;
    import org.bukkit.block.Dropper;
    import org.bukkit.block.Furnace;
    import org.bukkit.block.Hopper;
    import org.bukkit.block.Jukebox;
    import org.bukkit.block.NoteBlock;
    import org.bukkit.block.Sign;
    import org.bukkit.block.Skull;
    import org.bukkit.inventory.BeaconInventory;
    import org.bukkit.inventory.Inventory;
    import org.bukkit.inventory.InventoryHolder;
    
    import com.bergerkiller.bukkit.common.filtering.Filter;
    import com.noxpvp.core.NoxCore;
    import com.noxpvp.core.data.Pair;
    
    public class BlockStateUtils {
    	
    	public static boolean blockStatesMatch(BlockState state1, BlockState state2, Filter<Pair<BlockState>>... filters)
    	{
    		Pair<BlockState> states = new Pair<BlockState>(state1, state2);
    		
    		for (Filter<Pair<BlockState>> filter : filters)
    			if (!filter.isFiltered(states))
    				return false;
    		return true;
    	}
    	
    	public static boolean blockStatesPerfectMatch(BlockState state1, BlockState state2)
    	{
    		if (!state1.getBlock().equals(state2.getBlock()))
    			return false;
    		
    		if (!state1.getType().equals(state2.getType()))
    			return false;
    		
    		if (state1 instanceof Chest) { // No need to check other state for instance since they both match types!
    			if (!isChestMatch((Chest)state1, (Chest)state2))
    				return false;
    		} else if (state1 instanceof Beacon) {
    			if (!isBeaconMatch((Beacon)state1, (Beacon)state2))
    				return false;
    		} else if (state1 instanceof BrewingStand) {
    			if (!isBrewingStandMatch((BrewingStand)state1, (BrewingStand)state2))
    				return false;
    //		} else if (state1 instanceof Dispenser) {
    //			if (!isInventoryHolderMatch((InventoryHolder)state1, (InventoryHolder) state2))
    //				return false;
    //		} else if (state1 instanceof Dropper) {
    //			if (!isDropperMatch((Dropper)state1, (Dropper) state2))
    //				return false;
    //		} else if (state1 instanceof Hopper) {
    //			if (!isHopperMatch((Hopper)state1, (Hopper)state2))
    //				return false;
    		} else if (state1 instanceof Furnace) {
    			if (!isFurnaceMatch((Furnace)state1, (Furnace)state2))
    				return false;
    		} else if (state1 instanceof InventoryHolder) { ///Must come after Furnace (As its also an inventory holder!)
    			if (!isInventoryHolderMatch((InventoryHolder)state1, (InventoryHolder)state2))
    				return false;
    		} else if (state1 instanceof CommandBlock) {
    			if (!isCommandBlockMatch((CommandBlock)state1, (CommandBlock)state2))
    				return false;
    		} else if (state1 instanceof CreatureSpawner) {
    			if (!isSpawnerMatch((CreatureSpawner)state1, (CreatureSpawner)state2))
    				return false;
    		} else if (state1 instanceof Jukebox) {
    			if (!isJukeboxMatch((Jukebox)state1, (Jukebox)state2))
    				return false;
    		} else if (state1 instanceof NoteBlock) {
    			if (!isNoteBlockMatch((NoteBlock)state1, (NoteBlock)state2))
    				return false;
    		} else if (state1 instanceof Sign) {
    			if (!isSignMatch((Sign)state1, (Sign)state2))
    				return false;
    		} else if (state1 instanceof Skull) {
    			if (!isSkullMatch((Skull)state1, (Skull)state2))
    				return false;
    		}
    		
    		return true;
    	}
    	
    	private static boolean isSkullMatch(Skull state1, Skull state2) {
    		if (!state1.getSkullType().equals(state2.getSkullType()))
    			return false;
    		
    		if (!state1.getRotation().equals(state2.getRotation()))
    			return false;
    		
    		if (!state1.getOwner().equals(state2.getOwner()))
    			return false;
    		
    		return true;
    	}
    
    	private static boolean isSignMatch(Sign state1, Sign state2) {
    		for (int i = 0; i < 3; i++)
    			if (!state1.getLine(i).equals(state2.getLine(i)))
    				return false;
    		
    		return true;
    	}
    
    	private static boolean isNoteBlockMatch(NoteBlock state1, NoteBlock state2) {
    		if (!state1.getNote().equals(state2.getNote()))
    			return false;
    		
    		return true;
    	}
    
    	private static boolean isJukeboxMatch(Jukebox state1, Jukebox state2) {
    		if (!state1.getPlaying().equals(state2.getPlaying()))
    			return false;
    		
    		return true;
    	}
    
    	private static boolean isHopperMatch(Hopper state1, Hopper state2) {
    		return isInventoryHolderMatch(state1, state2);
    	}
    	
    	private static boolean isDropperMatch(Dropper state1, Dropper state2) {
    		return isInventoryHolderMatch(state1, state2);
    	}
    
    	private static boolean isFurnaceMatch(Furnace state1, Furnace state2) {
    		if (state1.getBurnTime() != state2.getBurnTime())
    			return false;
    		if (state1.getCookTime() != state2.getCookTime())
    			return false;
    		
    		return isInventoryHolderMatch(state1, state2);
    	}
    
    	private static boolean isInventoryHolderMatch(InventoryHolder state1, InventoryHolder state2) {
    		Inventory inv1 = state1.getInventory(), inv2 = state2.getInventory();
    		
    		if (inv1.getSize() != inv2.getSize())
    			return false;
    		
    		if (!inv1.getName().equals(inv2.getName()))
    			return false;
    		
    		if (!inv1.getTitle().equals(inv2.getTitle()))
    			return false;
    		
    		for (int i = 0; i < inv1.getSize(); i++)
    			if (!inv1.getItem(i).equals(inv2.getItem(i)))
    				return false;
    		
    		return true;
    	}
    
    	private static boolean isSpawnerMatch(CreatureSpawner state1, CreatureSpawner state2) {
    		if (!state1.getSpawnedType().equals(state2.getSpawnedType()))
    			return false;
    		
    		if (!state1.getCreatureTypeName().equals(state2.getCreatureTypeName()))
    			return false;
    		
    		if (state1.getDelay() != state2.getDelay())
    			return false;
    		
    		return true;
    	}
    
    	private static boolean isCommandBlockMatch(CommandBlock state1, CommandBlock state2) {
    		if (!state1.getName().equals(state2.getName()))
    			return false;
    		
    		if (!state1.getCommand().equals(state2.getCommand()))
    			return false;
    		
    		return true;
    	}
    
    	private static boolean isBrewingStandMatch(BrewingStand stand1, BrewingStand stand2)
    	{
    		//TODO: Determine if we wanna match items brewing and such
    		return true;
    	}
    	
    	private static boolean isBeaconMatch(Beacon beacon1, Beacon beacon2)
    	{
    		Inventory rInv1 = beacon1.getInventory(), rInv2 = beacon2.getInventory();
    		
    		try {
    			BeaconInventory inv1 = (BeaconInventory)rInv1, inv2 = (BeaconInventory)rInv2;
    			
    			if (!inv1.getItem().equals(inv2.getItem()))
    				return false;
    				
    		} catch (ClassCastException e) {
    			NoxCore.getInstance().log(Level.SEVERE, "Bukkit is not using their own api for beacons! SUBMIT BUT REPORT TO THEM! \n Defaulting to Plain inventory Code!");
    			return isInventoryHolderMatch(beacon1, beacon2);
    		}
    		return true;
    	}
    	
    	private static boolean isChestMatch(Chest state1, Chest state2)
    	{
    		return isInventoryHolderMatch(state1, state2);
    	}
    }
    
    
    

    public by temuraru  2445  1  4  0

    DB(store, schema) | Store Data in localStorage

    // Local Data
       
    function DB(store, schema) {
          this.store = store;
          if (!localStorage[store] || typeof localStorage[store] == 'undefined') {
              localStorage[store] = JSON.stringify(schema|| {});
          }
          this.setData = function (key, val) {
              var lda = JSON.parse(localStorage[this.store]);
              doUpdate(ldta, key, val);
              localStorage[store] = JSON.stringify(ldta);
          };
          this.getData = function (key) {
              var ldta = JSON.parse(localStorage[this.store]);
              if (key) {
                  return pathGet(ldta, key);
              }
              return ldta;
          };
          this.reset = function (schema) {
              localStorage[this.store] = JSON.stringify(schema || {});
          };
          this.delete = function() {
              localStorage.removeItem(this.store);
          };
          var doUpdate = function (ob, kStr, val) {
              var kpth = keyStr.split('.'),
              i = 0, lstIdx = kpth.length - 1;
              for (;i < lstIdx; ++i) {
                  var key = kpth[i];
                  if (!(key in ob)) {
                      ob[key] = {};
                  }
                  ob = ob[key];
              }
              ob[kpth[lstIdx]] = val;
          };
          var pathGet = function (obj, key, leftOvrs) {
              if ( leftOvrs === undefined ) {
                  leftOvrs = key.split('.');
              }
              var cur = leftOvrs.shift();
              if ( typeof(obj) == 'object' && obj[cur] !== undefined ) {
                  if ( leftOvrs.length === 0 ) {
                      return obj[cur];
                  }
                  else if ( typeof(obj[cur]) == 'object' ) {
                      return arguments.callee(obj[cur], undefined, leftOvrs);
                  }
              }
              return null;
          };
      }

    public by simonwalker  1104  0  6  0

    Magento GeoIP Store Switcher Extension | FME

    Magento GeoIP Store Switcher by FME is a geo-targeting extension which detects the visitor’s real-time location and redirects them to a region customized store view. Using this Magento GeoIP store switcher extension, you can create multiple store views, customize their theme, and display relevant products on the front. Allow the visitors to manuall
    // https://www.fmeextensions.com/magento-geo-ip-default-store-view.html        

    public by simonwalker  889  0  3  0

    Magento Google Map Store Locator Extension by FME

    Magento Google Map Store Locator extension by FME allows you to create a store finder page in your webshop. An exciting feature of this extension is that customers can search the store by product, address, or zip code. This Magento Google Map store locator extension also integrates Google Map to the store finder page where can display all the offli
    cpp
    // Enter here the actual content of the snippet.            						
    • Public Snippets
    • Channels Snippets