working on it ...

Filters

Explore Public Snippets

Sort by

Found 11k snippets matching: basic

    public by lbottaro modified Mar 12, 2014  428932  11  7  3

    HTML header - footer layout using CSS and DIV

    This code renders a HTML basic layout with header, main and footer contents. The main content has 2 columns and the right one contains two rows. Source: http://stackoverflow.com/questions/6778808
    <html>
        <head>
        <style type="text/css">
        #maincontent {
            width:950px;
            height:100%;
            margin:0 auto;
        }
        #header {
            width:946px;
            height:150px;
            border:#000 solid;
            border-width:2px 2px 1px 2px;
        }
        #leftcolumn {
            width:395px;
            height:703px;
            border:#000 solid;
            border-width:1px 1px 1px 2px;
            float:left;
        }
        #toprow {
            width:549px;
            height:351px;
            border:#000 solid;
            border-width:1px 2px 1px 1px;
            float:left;
        }
        #bottomrow {
            width:549px;
            height:350px;
            border:#000 solid;
            border-width:1px 2px 1px 1px;
            float:left;
        }
        #footer {
            width:946px;
            height:150px;
            border:#000 solid;
            border-width:1px 2px 2px 2px;
            clear:both;
        }
        </style>
        <body>
        <div id="maincontent">
            <div id="header">Header Content</div>
            <div id="leftcolumn">Leftcolumn Content</div>
            <div id="toprow">Toprow Content</div>
            <div id="bottomrow">Bottomrow Content</div>
            <div id="footer">Footer Content</div>
        </div>
        </body>
        </html>

    public by Uriahs modified Jun 29, 2015  310190  1  6  0

    Move borderless form VB.NET

    Code to move a borderless winform which is not moveable by default
    Dim drag As Boolean
       Dim mousex As Integer
       Dim mousey As Integer
       Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
           drag = True 'Sets the variable drag to true.
           mousex = Windows.Forms.Cursor.Position.X - Me.Left 'Sets variable mousex
           mousey = Windows.Forms.Cursor.Position.Y - Me.Top 'Sets variable mousey
       End Sub
    
       Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
           'If drag is set to true then move the form accordingly.
           If drag Then
               Me.Top = Windows.Forms.Cursor.Position.Y - mousey
               Me.Left = Windows.Forms.Cursor.Position.X - mousex
           End If
       End Sub
    
       Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
           drag = False 'Sets drag to false, so the form does not move according to the code in MouseMove
       End Sub
    

    public by lbottaro modified Mar 23, 2014  281150  2  6  3

    Simple RMI Java server

    This code shows a basic RMI server example. A "server" is the class which has a main method that creates an instance of the remote object implementation, exports the remote object and then binds that instance to a name in a RMI registry. Here the server implements the remote interface Hello. The class that contains this main method could be the
    package example.hello;
    	
    import java.rmi.registry.Registry;
    import java.rmi.registry.LocateRegistry;
    import java.rmi.RemoteException;
    import java.rmi.server.UnicastRemoteObject;
    	
    public class Server implements Hello {
    	
        public Server() {}
    
        public String sayHello() {
    	return "Hello, world!";
        }
    	
        public static void main(String args[]) {
    	
    	try {
    	    Server obj = new Server();
    	    Hello stub = (Hello) UnicastRemoteObject.exportObject(obj, 0);
    
    	    // Bind the remote object's stub in the registry
    	    Registry registry = LocateRegistry.getRegistry();
    	    registry.bind("Hello", stub);
    
    	    System.err.println("Server ready");
    	} catch (Exception e) {
    	    System.err.println("Server exception: " + e.toString());
    	    e.printStackTrace();
    	}
        }
    }    

    public by michaelp modified Apr 10, 2013  159247  0  3  0

    Basic way to calculate length of a string

    Basic way to calculate length of a string: gistfile1.txt
    # breaks if string includes a 0
    def string_length(a)
      string = a + "0"
      length = 0
    
      while string[length] != "0"
        length += 1
      end
    
      puts "Your statement is #{length} characters long"
    end
    
    string_length("I am a meat popsicle.")
    
    

    public by christopher modified Dec 31, 2013  169433  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 strykerraven modified Sep 22, 2016  187928  3  5  1

    WordPress safely defining and executing functions

    Handy safe way to include functions in your WordPress Themes functions.php file. This is even more useful if you are using a child theme and don't want to conflict with functions already defined by the parent theme. Even better; These functions can be executed within the same if(function_exists()) block that defines them creating a neater to manage
    <?php
    
    // Lets get rid of the versioning on static .js and .css files.
    // It looks tacky anyway for static files.
    
    	/**
    	 * Strips Version query strings
    	 * @param type $src
    	 * @return type
    	 */
    	if(!function_exists('remove_css_js_versions')){ // if the function doesnt exist then...
    		function remove_css_js_versions($src){ // define the function
    			return remove_query_arg('ver', $src); // call built-in wordpress function to remove query named "ver" from whatever is passed as $src
    		}
    		add_filter('script_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for js to function listed above named "remove_css_js_versions"
    		add_filter('style_loader_src', 'remove_css_js_versions'); // Pass a hook as $src for css to function listed above named "remove_css_js_versions"
    	} // All scripts and styles will be filtered to have ?ver=1.2.3 stripped from urls. Function defined and executed in same if() statement.
    
      /**
      * Need to debug? Instead of just using print_r($array) you just do preprint_r($array)
      * the array will be output neatly instead of wrapped and messy.
      */
    	if(!function_exists('preprint_r')){
    		function preprint_r($val){
    			echo '<pre>' . PHP_EOL;
    			print_r($val) . PHP_EOL;
    			echo '</pre>' . PHP_EOL;
    		}
    	}
    	
    	/** Remove the WP Icon (Menu) from profile and admin pages. */
    		if(!function_exists('remove_wp_logo')){
      		function remove_wp_logo($wp_admin_bar){
      			$wp_admin_bar->remove_node('wp-logo');
      		}
      		add_action('admin_bar_menu', 'remove_wp_logo', 33);
      	}
      	
    /**
    	 * Wordpress Login Page fixes. By default WordPress shows its logo on your login pages and links to its own site.
    	 * A visitor logging into your site don't need this potential roadblock so lets show WordPress that we mean business!
    	 */
    	# Fix Login Page WordPress URL
    	if(!function_exists('fix_wp_login_img_url')){
    		function fix_wp_login_img_url($url){
    			return get_bloginfo('url');
    		}
    		add_filter('login_headerurl', 'fix_wp_login_img_url');
    	}
    
    	# Fix Login Page WordPress Title (Text displayed on hover defaults to Powered By WordPress)
    	if(!function_exists('fix_wp_login_img_title')){
    		function fix_wp_login_img_title($title){
    			return get_bloginfo('description');
    		}
    		add_filter('login_headertitle', 'fix_wp_login_img_title');
    	}
    
    	/**
    		Change Login Page WordPress Logo, You will need to update path and point to a valid image.
    		WordPress adds this with a CSS background image for your anchor link. It first applys a PNG and then a SVG override if your browser is modern and supports svg
    		In your themes custom stylesheet you can change default Wordpress image by supplying a new background image:
    
    		.login h1 a {
    			background-image: none,url(images/your_image.png);
    		}
    
    		Hint: WordPress uses an 64x64 image but you can adapt size to your need. You might want to use SVG like WordPress did because it will scale best at any resolution.
    
    	 */
    
    	/**
    	 * Simple Actions that use wp_head hook to cleanup WP header Junk/Bloat
    	 * that is included with WordPress by default.
    	 */
    	remove_action('wp_head', 'wp_generator');
    	remove_action('wp_head', 'rsd_link');
    	remove_action('wp_head', 'wlwmanifest_link');
    	remove_action('wp_head', 'wp_shortlink_wp_head');            
    	
    	
    	?>

    public by passh modified Oct 19, 2016  10072  8  4  1

    HTML TWIG TEMPLATE BASIC

    basic twig html template
    {# HTML TEMPLATE TWIG TEMPLATE BASIC by Passh#}
    <!DOCTYPE HTML>
    
    <html lang="es">
    	<body>
    
    			<head>
    					<meta charset="utf-8" />
    					<title>
    							{% block titulo %} 
    								HTML TWIG TEMPLATE
    							{%endblock%}
    					</title>
    			</head>
    	</body>
    	<footer>by Passh</footer>
    </html>

    public by gonelf modified May 23, 2014  2495  1  5  1

    iOS tableview basic functions

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return [allCategories count];
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
        return 54;
    }
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        // select this skills
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
        static NSString *simpleTableIdentifier = @"feedCell";
        
        feedTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
        
        return cell;
    }

    public by Thomas Callahan modified Jul 12, 2016  1733  0  3  0

    Basic Alert Box using JS

    Basic Alert Box using JS: Basic alert
    <!DOCTYPE html>
    <html>
    <body>
    
    	<p>Click the button to display an alert box.</p>
    
    	<button onclick="myFunction()">Click me</button>
    
    	<script>
    		function myFunction() {
    			
    			alert("I am an alert box!");
    			
    		}
    	</script>
    
    </body>
    </html>
    
    

    public by lbottaro modified Oct 3, 2013  4113  14  7  0

    Basic OpenDaylight Python API

    This code shows a simple ODL API to connect to the server, to handle json response, to report error conditions etc... See more on ODL: OpenDaylight main site: [http://www.opendaylight.org/] (http://www.opendaylight.org/) OpenDaylight example project on github: [https://github.com/dwcarder/python-OpenDaylight/] (https://github.com/dwcarde
    from OpenDaylight import OpenDaylight
    from OpenDaylight import OpenDaylightFlow
    
    odl = OpenDaylight()
    odl.setup['hostname'] = '10.10.10.1'
    odl.setup['username'] = 'admin'
    odl.setup['password'] = 'admin'
    
    SWITCH_1 = '99:99:99:00:00:00:01:00'
    flow = OpenDaylightFlow(odl)
    node = OpenDaylightNode(odl)
    
    odl_test_flow_1 = {u'actions': u'DROP',
               u'etherType': u'0x800',
               u'ingressPort': u'1',
               u'installInHw': u'true',
               u'name': u'odl-test-flow1',
               u'node': {u'@id': SWITCH_1, u'@type': u'OF'},
               u'priority': u'500'}
    
    # add the flow
    flow.add(self.odl_test_flow_1) 
    
    # get this flow
    flow.get(node_id=SWITCH_1, flow_name='odl-test-flow1')
    
    # get all flows
    flow.get()
    
    # delete the flow
    flow.delete(SWITCH_1, 'odl-test-flow1')
    • Public Snippets
    • Channels Snippets