Skip to content

Instantly share code, notes, and snippets.

View iruslani's full-sized avatar

Iwan iruslani

View GitHub Profile
@iruslani
iruslani / getURLvars.js
Created May 9, 2012 22:30
Simple Javascript function to grab the parameter in the url and send an alert.
<script type="text/javascript">
$(document).ready(function(){
$.urlParam = function(name){
var results = new RegExp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href);
return results[1] || 0;
}
// example.com?param1=name&param2=&id=6
alert($.urlParam('param1')); // name
alert($.urlParam('question')); // name
alert(decodeURIComponent($.urlParam('question')));
@iruslani
iruslani / remove-dash-example.js
Created May 9, 2012 23:54
JS Function to remove dashes. You can use it for other characters as well by changing the js regular expression.
<script type="text/javascript">
$(document).ready(function(){
$.cleanString = function(testString) {
var numericString = testString.replace(/-/gi," ");
// .replace() uses regular expression. In this case, its replaceing '-' with ' '.
return numericString;
}
var question = "Sample-text-with-some-dashes";
var cleaned = $.cleanString(question);
@iruslani
iruslani / Simple htmlcss Layout
Created May 16, 2012 18:10
HTML/CSS layout utilizing floats and clear
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<!-- See http://www.alistapart.com/articles/css-floats-101/ -->
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>CSS Floats 101</title>
<style>
body {
margin: 0;
padding: 0;
@iruslani
iruslani / HTMLCSS with Positions
Created May 16, 2012 21:02
HTML/CSS layout utilizing positions: Static, relative, absolute and fixed
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Example J</title>
<style>
body {
margin: 0;
font: normal 12px/18px 'Helvetica', Arial, sans-serif;
@iruslani
iruslani / scroll_anchor_link.htm
Created May 25, 2012 20:38
An anchor link that scrolls the browser to the anchor link on the page.
@iruslani
iruslani / gist:2846829
Created May 31, 2012 22:34
Simple RSS Feed jquery
<html>
<head>
<script type="text/javascript" src="http://download.zonealarm.com/bin/promotions/pumpitup/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="http://www.zazar.net/developers/jquery/zrssfeed/jquery.zrssfeed.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
$('#test').rssfeed('http://www.securelist.com/en/rss/descriptions', {
@iruslani
iruslani / Checkbox jquery change
Created June 1, 2012 22:30
Change the url of the button depending if the checkbox is checked.
<html>
<head></head>
<body>
<!-- This checkbox is checked and cannot be unchecked -->
<input type="checkbox" name="fw" id="freefw" checked disabled />
<!-- If this checkbox changes, see jquery below -->
<input type="checkbox" name="av" id="freeavfw" />
@iruslani
iruslani / Sync 2 sets of radio buttons
Created June 6, 2012 18:52
This is an example of how to use a jquery variable inside a selector
$('form#zaav_a input:radio, form#zaav_b input:radio').click(function(){
// store variable class in this variable:
whichOne = $(this).attr("class");
// use variable name as a selector to select twin radio button mark as checked:
$('.' +whichOne).attr("checked", "checked");
@iruslani
iruslani / JS Object Literals
Created June 12, 2012 20:39
The basic JavaScript Object
var myObject = {
sayHello : function() {
console.log('hello');
},
myName : 'Iwan'
};
myObject.sayHello(); // logs 'hello'
console.log(myObject.myName); // logs 'Iwan'
@iruslani
iruslani / gist:2920427
Created June 12, 2012 22:07
Basic Javascript function Syntax.
// A simple function
var greet = function(person, greeting) {
var text = greeting + ', ' + person;
console.log(text);
};
greet('Iwan', 'Hello');
// A Function that returns a value