Skip to content

Instantly share code, notes, and snippets.

View hasinhayder's full-sized avatar
🚀
Back on track, yayyyy!

Hasin Hayder hasinhayder

🚀
Back on track, yayyyy!
View GitHub Profile
@hasinhayder
hasinhayder / fetch.php
Last active August 29, 2015 13:57
A new twig function which can fetch external URL via GET or POST and pass arbitrary parameters while fetching
<?php
//file: fetch.php
use Twig_Extension;
use Twig_Function_Method;
class Fetch extends Twig_Extension
{
public function fetch ($url, $params=array())
{
if($url){
$ch = curl_init($url);

Keybase proof

I hereby claim:

  • I am hasinhayder on github.
  • I am hasin (https://keybase.io/hasin) on keybase.
  • I have a public key whose fingerprint is 8319 D4D0 29CE 3C50 F788 D033 95EB 88C0 DF4D 79A3

To claim this, I am signing this object:

@hasinhayder
hasinhayder / cdn.php
Created July 1, 2014 13:47
Replace uploaded image urls by CDN
<?php
function change_to_cdn_url() {
return 'http://your.cdn.url/wp-content/uploads';
}
add_filter( 'pre_option_upload_url_path', 'change_to_cdn_url' );
@hasinhayder
hasinhayder / fetch attachment
Last active August 29, 2015 14:06
fetch media attachments via javascript in wp
for(i=0;i<selected_ids.length;i++){
if(selected_ids[i]>0){
var attachment = new wp.media.model.Attachment.get(selected_ids[i]);
attachment.fetch({success:function(att){
container.append("<li><img src='" + att.attributes.sizes.thumbnail.url + "'</li>");
}});
}
}
@hasinhayder
hasinhayder / wp_adjacent_posts_links.php
Created October 10, 2014 18:43
Getting link for next and previous post in WordPress
def main():
print max([2,3,4,5,1,2,11,2,8,3,10])
def max(nums):
_max=nums[0]
for n in nums:
_max = _max if (_max>n) else n
return _max
if __name__ == "__main__": main()
@hasinhayder
hasinhayder / gist:b2f61dc219557eb9e06d
Last active August 29, 2015 14:15
counter problem :)
var counter = function(arg){
var local;
function incr(arg2){
arg2 = arg2 == undefined ? 1 : arg2;
return !local ? (local = arg2, incr) : (local += arg2, local);
}
return incr(arg);
}
var cnt = counter(5);
@hasinhayder
hasinhayder / gist:60c4fa9ca16a31ab8763
Created February 18, 2015 19:39
counter problem v 2
var counter = function(arg){
arg = arg == undefined ? 1 : arg;
var me = arguments.callee;
return me.count ? ( me.count += arg, me.count ) : ( me.count = arg, me );
}
var cnt = counter(5);
cnt();
cnt();
console.log(cnt(5)); //shud return 12
@hasinhayder
hasinhayder / im.js
Created February 23, 2015 22:52
Immutability via __defineGetter__
var me = {
_first:"Count",
_last: "Dracula";
}
me.__defineGetter__('first', function() { return this._first; });
me.__defineGetter__('last', function() { return this._last; });
me.first= "Die!";
console.log(me.first); //still shows "Count"
@hasinhayder
hasinhayder / gist:5886783
Last active December 19, 2015 02:59
Change number of posts displayed in WordPress blog page by weekdays
function number_of_posts_per_day($query){
if (date("l")=="Sunday") {
$query->set('posts_per_page', 20);
}
elseif (date("l")=="Monday") {
$query->set('posts_per_page', 10);
}
elseif (date("l")=="Tuesday") {
$query->set('posts_per_page', 5);
}